Doubt - can solve this way?

Why we cannot use direct mathematics in this ques. Lets say M be the total number of coupns we already have Y be the no of coupns we borrow

means total no of coupns will be M+Y

Since each student require X coupns

Therefore max no of students will be (M+Y)/X

As much as I can think, this will give the max number of students that can avail scholarship…

Please clarify the doubt

Hello @akhil54,

You need to modify your equation.
Y is the number of coupons received from students who performed badly.
So, the total number of coupons received will be,
= (count of bad students)*Y
= cnt * Y

So, maximum number of students, ans = ( M + cnt*Y)/X

Also, Total students can’t be greater than N, ans + cnt = N

@akhil54, Is it clear now?

NO, didnot get. Please explain

@akhil54,

In your equation, you are taking only one Y, as if only one student might perform badly.
If 3 students performed badly then, total coupons received = M + 3*Y and not M + Y.

How is it considered in question then?

@akhil54,

It is written in the problem statement that,
some students who performs badly, needs to pay Y discount coupons.

So, for each student you need to add Y coupons, hence cnt*Y ( cnt = number of bad students)

Yes, that I got. But i am not getting, how to find the number of bad students, its not given in ques.

@akhil54,

The number of bad students are not provided to you but you can binary search over that value to find optimal value for the number of good students.

According to the problem,

Now, to solve the above equation you need to choose some value of cnt and solve the equation, similarly try for other possible values of cnt.

Also possible values of cnt ranges from 0 to n.

It means while checking the max number of students, we have to again use a loop to find how many times the sum of tokens given by each student become greater than required tokens to get the scholarship. Then increase the number of students and delete one student from main array

or there should be different approach

Hello @akhil54,

Should I share my implementation? It would be more easy for you to understand then.

No no, please do let me try, If i have a doubt, i will ask for it.

@akhil54
okay sure .

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.