水题, 排序, 贪心
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namespace std; const int maxn = 20001; int main() { //freopen("D:\\t.txt", "r", stdin); int n, b; scanf("%d%d", &n, &b); int cow[maxn]; for (int i = 0; i < n; i++) scanf("%d", &cow[i]); sort(cow, cow + n); int sum = 0; int i = n; while (sum < b) { i--; sum += cow[i]; } printf("%d\n", n - i); return 0; }