Run ID:99404

提交时间:2024-11-27 20:24:25

#include <bits/stdc++.h> int w,n,ans,p[30005],r; bool cmp(const int &a,const int &b){ return a>b; } int main(){ scanf("%d%d",&w,&n); for(int i=1;i<=n;i++) scanf("%d",&p[i]); std::sort(p+1,p+n+1,cmp); r=n; for(int i=1; ;i++){ if(p[i]+p[r]>w && i!=r){ ans++; p[i]=0; } else{ ans++; p[i]=0; p[r]=0; r--; } bool ok=true; for(int i=1;i<=n;i++) if(p[i]!=0){ ok=false; break; } if(ok) break; } printf("%d",ans); return 0; }