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:
parent
0c2217509e
commit
06da1a30b2
26
problem/P1094/P1094.cpp
Normal file
26
problem/P1094/P1094.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user