AC

你干嘛~~嗨嗨哟~~  •  6个月前


include <bits/stdc++.h>

using namespace std; int w, n, t[30005], boat[30005];

int cmp(int x, int y) {

return x > y;

}

int main() {

cin >> w >> n;
for (int i = 1; i <= n; i++)
	cin >> t[i];
sort(t + 1, t + 1 + n, cmp);
fill(boat, boat + 30005, w);
int ans = 0, bnum = 1, i = 0, k;
while (i < n) {
	i++;
	for (bnum = 1;; bnum++) {
		k = bnum;
		if (boat[bnum] >= t[i]) {
			if (boat[bnum] != w)
				boat[bnum] = 0;
			else
				boat[bnum] -= t[i];
			break;
		}
	}
	ans = max(ans, k);

}
cout << ans;
return 0;

}


评论:

请先登录,才能进行评论