比赛 |
test1 |
评测结果 |
AAAAAAAAAAA |
题目名称 |
纪念品分组 |
最终得分 |
100 |
用户昵称 |
TARDIS |
运行时间 |
0.040 s |
代码语言 |
C++ |
内存使用 |
0.39 MiB |
提交时间 |
2017-02-28 20:18:57 |
显示代码纯文本
- #include<iostream>
- #include<cstdio>
- #include<cmath>
- #include<algorithm>
- #define maxn 30001
- using namespace std;
- int w,n,p[maxn];int ans=0;
- inline void readln(){
- freopen("group.in","r",stdin);
- freopen("group.out","w",stdout);
- scanf("%d%d",&w,&n);
- for (int i=1;i<=n;i++){
- scanf("%d",&p[i]);
- }
- }
- inline void work(){
- sort(p+1,p+n+1);
- int l=1,r=n;
- while(l<=r){
- if (p[l]+p[r]<=w){
- ans++;l++;r--;
- }
- else {
- ans++;r--;
- }
- }
- printf("%d\n",ans);
- }
- int main(){
- readln();
- work();
- fclose(stdin);fclose(stdout);
- return 0;
- }