149A Codeforces - Business Trip


149A Codeforces - Business Trip



Solution in c++

#include <iostream>
#include <algorithm>

using namespace std;

int n,sol,acc;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n;int nn[12];
    for(int i=0;i<12;i++)cin>>nn[i];
    sort(nn,nn+12,greater<int>());
    for(int i=0;i<12;i++)
    {
        if(acc>=n)
        {
            cout<<sol<<"\n";
            return 0;
        }
        else
        {
            acc+=nn[i];
            sol++;
        }
    }
    if(acc<n)sol=-1;
    cout<<sol;
    return 0;
}

Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق