Given N different candies and M children. Each of the children demands for K[i]
different candies and will only be happy iff he get all those different candies which he demanded.
Now I want to maximize the number children that get happy. How should I distribute the candies?
Example: Let's have N=4
candies and M=3
children:
- 1st child requires 2 (K[1]) candies which are: 1 and 2
- 2nd child requires 2 (K[2]) candies which are: 2 and 3
- 3rd child requires 2 (K[3]) candies which are: 3 and 4
The answer here is 2 as I can at best only make the 1st and 3rd child happy.
My attempt:
Give candies to children in the order of the amounts that they require to be happy (i.e. K[i]). In other words, you should only give candy to a child if you have made happy all the children that demand less, and every time you give candy to one of them you have to give them the whole amount that they require.
Is this solution correct?