我们尽可能让最大的与最小的相加。
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e4+10;
int n,a[maxn],cnt,w;
int main(){
scanf("%d",&w);
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+1+n);
int p=1,q=n;
while(p<=q){
if(a[p]+a[q]<=w)cnt++,p++,q--;
else cnt++,q--;
}
printf("%d\n",cnt);
}