What is possibly wrong with my approach ? Winning CB Scholarship, it is giving right answer to my knowledge

public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int numStudents = sc.nextInt();
	int numCoupons = sc.nextInt();
	int perHeadCoupon = sc.nextInt();
	int finedCoupon = sc.nextInt();

	int scholarShipGiven = Math.min(numStudents, numCoupons / perHeadCoupon);
	int remainingStudent = numStudents - scholarShipGiven;
	int collectedCouponAsFine = remainingStudent * finedCoupon;
	int totalRemaningCoupon = collectedCouponAsFine+(numCoupons-(scholarShipGiven*perHeadCoupon));
	
	while((totalRemaningCoupon-finedCoupon) >= perHeadCoupon && remainingStudent > 0)
	{
		scholarShipGiven++;
		totalRemaningCoupon-=finedCoupon;
		remainingStudent--;
	}
	System.out.println(scholarShipGiven);
	sc.close();

}

?it should check one by one if its possible or not

@shahid.dhariwala your logic is not right .for
55 20 2 1 you should get 25 u are getting 53

Hmm thanks …

1 Like