Friday 17 February 2012

Codeforces Round #106 (Div. 2)


Codeforces Round #106 (Div. 2)

                                     A. BUSINESS TRIP
                                    

What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the i-th (1 ≤ i ≤ 12) month of the year, then the flower will grow by ai centimeters, and if he doesn't water the flower in the i-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by k centimeters.
Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by kcentimeters.
Input
The first line contains exactly one integer k (0 ≤ k ≤ 100). The next line contains twelve space-separated integers: the i-th (1 ≤ i ≤ 12) number in the line represents ai (0 ≤ ai ≤ 100).
Output
Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by kcentimeters. If the flower can't grow by k centimeters in a year, print -1.


#include<iostream>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<list>
#define show(x) copy(x.begin(),x.end(),output)
#include<iterator>
#define sort(x) sort(x.begin(),x.end())
#include<string>
#define vs vector<string>
#define vi vector<int>
#define pb push_back
#include<map>
#include<algorithm>
#include<sstream>
#include<stack>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<cctype>
using namespace std;



int main()
{
    int K = 0;
    int ret = 0;
    int sum = 0;
    int a1 = 0;
    vector<int>a;
    cin>>K;
    
    for(int i = 0 ; i < 12 ; i++)
    {
            cin>>a1;
            a.pb(a1);
    }
    sort(a.begin(),a.end());
    for(int j = a.size() - 1 ; j >= 0 ; j--)
    {
           sum = sum + a[j];
           ret++;
           if( sum >= K)
           {
               break;
           }
    }
    if( K == 0)
    {
        ret = 0;
        cout<<ret;
        return 0;
    }
    if(sum < K )
    {
           ret = -1;
           cout<<ret;
           return 0;
    }
    cout<<ret<<endl;
    cin.get();
    return 0;
}     
BY: SAURABH BHATIA(GNDU , RC JAL)

No comments:

Post a Comment