Problem Statement |
|||||||||||||
TopCoder admin mystic_tc is sitting in front of a table. He found N sealed boxes of candies on the table. He is not sure how many candies each box contains. However, he knows the following information:
You know that mystic_tc eats candies as follows: first he chooses a subset of the boxes, then he opens them and eats all the candies he found inside. He wants to eat at least X candies. And as he is smart, he will always choose a subset of boxes for which he is sure that they must contain at least X candies. You are given the ints C and X, and the vector <int> high. Return the smallest number of boxes mystic_tc may choose. |
|||||||||||||
Definition |
|||||||||||||
|
|||||||||||||
Limits |
|||||||||||||
|
|||||||||||||
Constraints |
|||||||||||||
- | high will contain between 1 and 50 elements, inclusive. | ||||||||||||
- | Each element of high will be between 1 and 50, inclusive. | ||||||||||||
- | C will be between 1 and the sum of all elements of high, inclusive. | ||||||||||||
- | X will be between 1 and C, inclusive. | ||||||||||||
Examples |
|||||||||||||
0) | |||||||||||||
|
|||||||||||||
1) | |||||||||||||
|
|||||||||||||
2) | |||||||||||||
|
|||||||||||||
3) | |||||||||||||
|
|||||||||||||
4) | |||||||||||||
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
class MysticAndCandiesEasy { public: int minBoxes(int C, int X, vector <int> h) { int n=h.size(),sum=C,ans=n; sort(h.begin(),h.end()); for(int i=0;i<n;i++) { if(sum-h[i]>=X) { sum=sum-h[i]; ans--; } } return ans; } };
SRM 608 div2 500 MysticAndCandiesEasy
原文:http://blog.csdn.net/u012797220/article/details/18996165