文章
34
粉丝
89
获赞
3
访问
20.5k
#include<bits/stdc++.h> using namespace std; const int maxn = 1005; int weight[maxn]; int main() { int n, w; while (scanf("%d%d", &n, &w) != EOF) { for (int i = 1; i <= n; i++) { scanf("%d", &weight[i]); } sort(weight + 1, weight + n + 1); int ans = 0; int index = 1; while (index <= n) { int curw = 0; while (curw < w) { curw += weight[index]; if (curw <= w) index++; } ans++; } printf("%d\n", ans); } return 0; }
登录后发布评论
暂无评论,来抢沙发