解题思路:
运用快排、while循环;
注意事项:
参考代码:
#include<bits/stdc++.h> using namespace std; long long n,b,a[20005]; bool cmp(int a,int b){ return a>b; } int main(){ cin>>n>>b; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+1+n,cmp); long long s=0,k=0; while(s<b){ k++; s+=a[k]; } cout<<k; return 0; }
0.0分
1 人评分