0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 20:36:28 +00:00

P1094 纪念品分组

R39868074
This commit is contained in:
Baoshuo Ren 2020-10-15 21:36:41 +08:00 committed by Baoshuo Ren
parent 0c2217509e
commit 06da1a30b2
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

26
problem/P1094/P1094.cpp Normal file
View File

@ -0,0 +1,26 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
int w, n, ans = 0, p[30005];
cin >> w >> n;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
sort(p, p + n);
int l = 0, r = n - 1;
while (l <= r) {
if (p[l] + p[r] <= w) {
l++;
r--;
ans++;
}
else {
r--;
ans++;
}
}
cout << ans << endl;
return 0;
}