// UVa 11900 - Boiled Eggs #include <iostream> #include <algorithm> #include <cstdio> using namespace std; int n, p, q; int w[30]; int calc() { int total_weight = 0; for (int i = 0; i < n && i < p; i++) { total_weight += w[i]; if (total_weight > q) return i; } return min(p,n); } int main() { int cases; cin >> cases; for (int c = 1; c <= cases; c++) { cin >> n >> p >> q; for (int i = 0; i < n; i++) cin >> w[i]; sort(w, w + n); printf("Case %d: %d\n", c, calc()); } return 0; }
No comments:
Post a Comment