这个哪里错了?50分求调!
查看原帖
这个哪里错了?50分求调!
1331158
yuer111楼主2024/9/4 11:32
#include<bits/stdc++.h>
using namespace std;
int w,n,p[3005],ans;
int main(){
	cin>>w>>n;
	for(int i=1;i<=n;i++)
		cin>>p[i];
	sort(p+1,p+1+n);
	int l=1,r=n;
	while(l<=r){
		if(p[l]+p[r]<=w){
			ans++;
			l++;
			r--;
		}
		else{
			ans++;
			r--;
		}
	}
	cout<<ans;
	return 0;
}
2024/9/4 11:32
加载中...