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();
}
What is possibly wrong with my approach ? Winning CB Scholarship, it is giving right answer to my knowledge
?it should check one by one if its possible or not
Hmm thanks …
1 Like