为什么用for循环不对呢
查看原帖
为什么用for循环不对呢
1443016
LLLLLLsy楼主2024/10/18 19:39
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool cmp(int c,int d){
	return c>d;
}
	
int main(){
	ll n,b,m=0,s=0;
	ll a[20002];
	cin>>n>>b;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a,a+n+1,cmp);
	for(int i=1;i<=n;i++){
		if(m<=b){
		m+=a[i];
		s++;
		
		}
	}cout<<s;
	return 0;
}
2024/10/18 19:39
加载中...