Bookshelf OpenJ_Bailian - 3406 (水题)

https://vjudge.net/problem/OpenJ_Bailian-3406

水题

//Bookshelf
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;

const int maxn = 20010;
int cows[maxn], N, B;;
int main()
{
    cin >> N >>B;
    for(int i = 1; i <= N; i++)
        cin >> cows[i];
    sort(cows+1, cows+N+1);
    int ans = 0, sum = 0;
    for(int i = N; i >= 1; i--){
        sum += cows[i], ans++;
        if(sum >= B) break;
    }
    printf("%d\n",ans);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/a1097304791/article/details/83065366