A8443 | Business trip
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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$ ).
输出格式
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.
输入输出样例
输入 #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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted