Problem Solution Ideas for the given problem ??

Revision en2, by sainiarpit12, 2016-02-16 13:50:44

There are n classes in which there are a1,a2,..an students in each class. You have given b cakes (b >= n) , you have to divide the cakes in each class such that the number of students per cake in each class is minimum and each class should have atleast 1 cake in it. You need to find the maximum number of students per cake in any class such that cakes are divided in each class optimally. How should I approach? First I give 1 cake to each class. Then I left with b-n cakes , how one should distribute it optimally ?? Lets say I give x1 cakes to class 1 and x2 to class 2 and so on such that x1+x2+..+xn = b and ans = find max( a1/x1 , a2/x2 ,...,an/xn) Sample Input 1 2 7 20 50 ans = 10 , I give 2 cake to class 1 and 5 cake to class 2. Sample Input 2 6 7 1 1 1 1 1 10 ans = 5 , I give 1 cake to first 5 class and then 2 to last class , so ans = 10/2 which is maximum . Thanks for any solutions.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English sainiarpit12 2016-02-16 13:50:44 2
en1 English sainiarpit12 2016-02-16 13:50:15 960 Initial revision (published)