Thứ Tư, 27 tháng 4, 2022

TONGSO C++

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

int n,k;
long long int a[100001];
int T = 0;
int dem = 0;
bool found = 0;

bool cmp(int x, int y)
{
    return x > y;
}
int main()
{
    freopen("tongso.inp","r",stdin);
    freopen("tongso.out","w",stdout);
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    sort(a+1,a+n+1,cmp);
    for(int i = 1; i <= n; i++)
    {
        T = T + a[i];
        dem++;
        if(T >= k)
        {
            found = 1;
            break;
        }
    }
    if(found == 1)
    {
        cout << dem;
    }
    else
    {
        cout << "0";
    }
    return 0;
}

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.