【Henu ACM Round#17 B】USB Flash Drives

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

排序,逆序。贪心选较大的就好。

【代码】

#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int M =1e5;

int f[M+10],a[1000+10],n,m;

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    #ifdef LOCAL_DEFINE
        freopen("rush.txt","r",stdin);
    #endif // LOCAL_DEFINE
    cin >> n >> m;
    for (int i = 1;i <= n;i++) cin >> a[i];
    sort(a+1,a+1+n);
    reverse(a+1,a+1+n);
    int cnt = 0;
    for (int i = 1;i <= n && m>0;i++){
        m-=a[i];
        cnt++;
    }
    cout <<cnt<<endl;
    return 0;
}
原文地址:https://www.cnblogs.com/AWCXV/p/8365505.html