CF149A.Business trip
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 a__i 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 k centimeters.
多么开心啊!佩佳的父母因公出差整整一年,活泼好动的孩子独自一人留在了家里。佩佳简直高兴坏了。他整天在床上蹦跳、扔枕头,直到……
今天,佩佳打开橱柜,发现里面有一张可怕的纸条。原来父母给他留下了一项任务:他必须在全年每天的早晨、下午和晚上给父母最喜爱的花浇水。“等等!”——佩佳心想。他清楚地知道,如果他在一年中的第 i(1≤i≤12)个月完成了父母交代的任务,则这株花当月将生长 ai 厘米;而如果他在第 i 个月没有给花浇水,则该月花不会生长。佩佳还知道,无论他怎么解释,只要花的总生长量严格小于 k 厘米,他的父母就绝不会相信他真的坚持给花浇了水。
请帮佩佳选出最少需要浇水的月份数,使得花的总生长量不少于 k 厘米。
输入格式
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 a__i (0 ≤ a__i ≤ 100).
第一行包含一个整数 k(0≤k≤100)。
下一行包含十二个用空格分隔的整数:该行中第 i 个数(1≤i≤12)表示 ai(0≤ai≤100)。
输出格式
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 k centimeters. If the flower can't grow by k centimeters in a year, print -1.
输出唯一的整数——Petya 至少需要浇水的月份数,使得花朵的生长量不少于 k 厘米。如果该花在一年内无法生长 k 厘米,则输出 −1。
输入输出样例
输入#1
5 1 1 1 1 2 2 3 2 2 1 1 1
输出#1
2
输入#2
0 0 0 0 0 0 0 0 1 1 2 3 0
输出#2
0
输入#3
11 1 1 4 1 1 5 1 1 4 1 1 1
输出#3
3
说明/提示
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.
我们来考虑第一个样例测试。在该样例中,只需在第七个月和第九个月给花浇水即可,这样花恰好长高 5 厘米。
在第二个样例中,即使花完全不生长(k = 0),Petya 的父母也会相信他。因此,Petya 完全可以不给花浇水。
输入解题思路,AI测评打分。不知道怎么写?