https://www.luogu.com.cn/problem/P2676
代码:
#include <bits/stdc++.h>
using namespace std;
#if 1
#define MAXN 20480
long long a[MAXN];
#endif // 0
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int n,x,i,y=0,cnt=0;
cin>>n>>x;
for(i=1; i<=n; i++)
{
cin>>a[i];
}
sort(a+1,a+n+1,cmp);
for(i=1; i<=n; i++)
{
if(y<x)
{
cnt++;
y=y+a[i];
}
else
{
break;
}
}
cout<<cnt<<endl;
return 0;
}