Codeforces Round #428 (Div. 2) A. Arya and Bran

来源:互联网 发布:崩坏3矩阵重置 编辑:程序博客网 时间:2024/05/16 16:13
A. Arya and Bran
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 aren days, at thei-th day, Arya findsai candies in a box, that is given by the Many-Faced God. Every day she can give Branat 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 then-th day. Formally, you need to output the minimum day index to the end of whichk candies will be given out (the days are indexed from 1 ton).

Print -1 if she can't give him k candies during n given days.

Input

The first line contains two integers n andk (1 ≤ n ≤ 100,1 ≤ k ≤ 10000).

The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).

Output

If it is impossible for Arya to give Bran k candies withinn days, print-1.

Otherwise print a single integer — the minimum number of days Arya needs to give Brank candies before the end of then-th day.

Examples
Input
2 31 2
Output
2
Input
3 1710 10 10
Output
3
Input
1 910
Output
-1
Note

In the first sample, Arya can give Bran 3 candies in2 days.

In the second sample, Arya can give Bran 17 candies in3 days, because she can give him at most8 candies per day.

In the third sample, Arya can't give Bran 9 candies, because she can give him at most8 candies per day and she must give him the candies within1 day.

扎心。。。这题最后还是错了

#include <iostream>#include <cstdio>#include <cstring>#include <queue>#include <algorithm>#define inf 0x3f3f3f3fusing namespace std;const int N = 550;int a[N];int main(){    int n,k;    scanf("%d%d",&n,&k);    int sum=0;    int f=0;    for(int i=0;i<n;i++)    {        scanf("%d",&a[i]);    }    int t=-1;    for(int i=0;i<n;i++)    {        int qu=0;        if(a[i]<=8)        {            qu = a[i];            if(sum+a[i]>=8)            {                sum-= 8 -a[i];                qu = 8;            }            else//漏掉了这种情况,即sum存在 且  加上现在的也给不足8颗糖            {                qu = sum+a[i];                sum=0;            }            k -= qu;        }        else        {            sum+=a[i]-8;            k-=8;        }        if(k<=0) {f=1;t=i+1;break;}    }     printf("%d\n",t);    return 0;}




原创粉丝点击