A. business trip

Source: Internet
Author: 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,...

Today Petya opened the cupboard and found a scary note there. his parents had left him with duties: He shocould water their favorite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second! "-Thought Petya. He know
A fact that if he fulfills the parents 'Task inI-Th (1 digit ≤ secondILimit ≤ limit 12)
Month of the year, then the flower will growAICentimeters,
And if he doesn' t water the flower inI-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 thanKCentimeters.

Help Petya choose the minimum number of months when he will water the flower, given that the flower shoshould grow no less thanKCentimeters.

Input

The first line contains exactly one integerK(0 bytes ≤ bytesKLimit ≤ limit 100 ).
The next line contains twelve space-separated integers:I-Th (1 digit ≤ secondILimit ≤ limit 12)
Number in the line representsAI(0 bytes ≤ bytesAILimit ≤ limit 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 thanKCentimeters.
If the flower can't growKCentimeters 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 (KRows = Limit 0). So, it is possible for Petya not
Water the flower at all.

Explanation of problem solving: sequence question, water question, Note 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;}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.