A. Business trip

來源:互聯網
上載者:User
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Sample test(s)input
51 1 1 1 2 2 3 2 2 1 1 1
output
2
input
00 0 0 0 0 0 0 1 1 2 3 0
output
0
input
111 1 4 1 1 5 1 1 4 1 1 1
output
3
Note

Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.

In the second sample Petya's parents will believe him even if the flower doesn't grow at all (k = 0). So, it is possible for Petya not to
water the flower at all.

解題說明:排序題,水題,注意k=0的情況

#include <iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;int main(){int i,j,k;int a[12];int temp;int sum;scanf("%d",&k);for(i=0;i<12;i++){scanf("%d",&a[i]);}for(i=0;i<12;i++){for(j=i+1;j<12;j++){if(a[i]<a[j]){temp=a[j];a[j]=a[i];a[i]=temp;}}}if(k==0){printf("0\n");}else{sum=0;for(i=0;i<12;i++){sum+=a[i];if(sum>=k){printf("%d\n",i+1);break;}}if(i==12){printf("-1\n");}}    return 0;}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.