比赛 test1 评测结果 AAAAAAAAAAA
题目名称 纪念品分组 最终得分 100
用户昵称 Hyoi_0Koto 运行时间 0.056 s
代码语言 C++ 内存使用 0.39 MiB
提交时间 2017-02-28 19:54:56
显示代码纯文本
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. using namespace std;
  5. int a,b[30001],n,ans=0,h=0,t;
  6. void input(){
  7. cin>>a>>n;
  8. for(int i=1;i<=n;i++) scanf("%d",&b[i]);
  9. }
  10. void work(){
  11. sort(b+1,b+n+1);t=n;
  12. while(h<t){
  13. if(b[h]+b[t]>a){
  14. t--;ans++;
  15. }
  16. else{
  17. h++;t--;ans++;
  18. }
  19. }
  20. if(h==t) cout<<ans+1;
  21. else cout<<ans;
  22. }
  23. int main(){
  24. freopen("group.in","r",stdin);
  25. freopen("group.out","w",stdout);
  26. input();
  27. work();
  28. return 0;
  29. }