传送门

先排序,然后从小到大直到够数了。

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 6600;
int x[maxn];
signed main()
{
    //freopen("in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,T;
    cin >> n >> T;
    for(int i = 1;i <= n; i++)
        cin >> x[i];
    sort(x + 1,x + 1 + n);
    int sum = 0,ans;
    for(int i = 1;i <= n; i++)
    {
        if(sum + x[i] > T)
            break;
        ans = i;
        sum += x[i];
    }
    cout << ans << endl;
    return 0;
}