A11136 | Arya and Bran
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have $0$ Candies. There are $n$ days, at the $i$ -th day, Arya finds $a_{i}$ candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most $8$ of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran $k$ candies before the end of the $n$ -th day. Formally, you need to output the minimum day index to the end of which $k$ candies will be given out (the days are indexed from 1 to $n$ ).
Print -1 if she can't give him $k$ candies during $n$ given days.
At first, Arya and Bran have $0$ Candies. There are $n$ days, at the $i$ -th day, Arya finds $a_{i}$ candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most $8$ of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran $k$ candies before the end of the $n$ -th day. Formally, you need to output the minimum day index to the end of which $k$ candies will be given out (the days are indexed from 1 to $n$ ).
Print -1 if she can't give him $k$ candies during $n$ given days.
输入格式
The first line contains two integers $n$ and $k$ ( $1<=n<=100$ , $1<=k<=10000$ ).
The second line contains $n$ integers $a_{1},a_{2},a_{3},...,a_{n}$ ( $1<=a_{i}<=100$ ).
The second line contains $n$ integers $a_{1},a_{2},a_{3},...,a_{n}$ ( $1<=a_{i}<=100$ ).
输出格式
If it is impossible for Arya to give Bran $k$ candies within $n$ days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran $k$ candies before the end of the $n$ -th day.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran $k$ candies before the end of the $n$ -th day.
输入输出样例
输入 #1
2 3 1 2
输出 #1
2
输入 #2
3 17 10 10 10
输出 #2
3
输入 #3
1 9 10
输出 #3
-1
In the first sample, Arya can give Bran $3$ candies in $2$ days.
In the second sample, Arya can give Bran $17$ candies in $3$ days, because she can give him at most $8$ candies per day.
In the third sample, Arya can't give Bran $9$ candies, because she can give him at most $8$ candies per day and she must give him the candies within $1$ day.
In the second sample, Arya can give Bran $17$ candies in $3$ days, because she can give him at most $8$ candies per day.
In the third sample, Arya can't give Bran $9$ candies, because she can give him at most $8$ candies per day and she must give him the candies within $1$ day.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted