题目:http://community.topcoder.com/stat?c=problem_statement&pm=12998
代码:
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <ctime>
using namespace std;
#define CHECKTIME() printf("%.2lf\n", (double)clock() / CLOCKS_PER_SEC)
/*************** Program Begin **********************/
class MysticAndCandiesEasy {
public:
int minBoxes(int C, int X, vector <int> high) {
int res = 0;
int N = high.size();
sort(high.begin(), high.end());
int sum = 0;
for (int i = 0; i < N; i++) {
sum += high[i];
}
int dif = sum - C;
reverse(high.begin(), high.end());
int eat = 0;
for (int i = 0; i < N; i++) {
eat += high[i];
if (eat - dif >= X) {
res = i + 1;
break;
}
}
return res;
}
};
/************** Program End ************************/
SRM 608 D2 L2:MysticAndCandiesEasy
原文:http://blog.csdn.net/xzz_hust/article/details/18988969