90pts求助
查看原帖
90pts求助
724593
Decepticon楼主2022/7/25 21:25
#include <bits/stdc++.h>
using namespace std;
int n,a[10000005];
long long w;
int ans,j,sum;

int main(){
	cin >> n;
	for(int i = 1; i <= n; i++)
	    cin >> a[i];
	sort(a+1,a+1+n);
	cin >> w;
	for(int i = n; i >= 1; i--){
		if(w >= a[i]){
		   w = a[i];
		   j = i;
		   break;
		}
	}
	for(int i = 1; i < j; i++){
		if(sum+a[i] < w){
		   ans++;
		   sum += a[i];
		} else if(sum+a[i] == w){
		   ans++;
		   sum += a[i];
		   break;
		} else {
		   break;
		}
	}
	cout << ans << endl;
	return 0;
}

为什么2WA

2022/7/25 21:25
加载中...