P1094 纪念品分组

https://www.luogu.org/problemnew/show/P1094

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <bits/stdc++.h>
using namespace std;

int num[1000010],n,w;

int main(void)
{
cin >> w >> n;

for(int i = 1;i <= n;++i)
cin >> num[i];

sort(num+1,num+n+1);

int ans = 0;
int l = 1,r = n;
while(l <= r)
{
if(num[l] + num[r] <= w)
ans++,l++,r--;
else
ans++,r--;
}

cout << ans;

return 0;
}
本站文章除注明转载外均为原创,未经允许不要转载哇. ヾ(゚ー゚ヾ) http://chicago01.top/2019/05/14/p1094-ji-nian-pin-fen-zu/index.html
Compartir