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 ai 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.

Input

The first line contains two integers n and k (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 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.

Examples
Input
2 3
1 2
Output
2
Input
3 17
10 10 10
Output
3
Input
1 9
10
Output
-1
Note

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.

 #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std; int main()
{
int n,k;
scanf("%d%d",&n,&k);
int a[],tmpk=,i;
bool flag=false;
for(i=;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=;i<n;i++)
{
if(a[i]>=)
{
tmpk+=;
a[i]-=;
a[i+]+=a[i];
}
else
{
tmpk+=a[i];
}
if(tmpk>=k)
{
flag=true;
break;
}
}
if(flag)
printf("%d\n",i+);
else
printf("-1\n");
return ;
}

codeforce 839A Arya and Bran(水题)的更多相关文章

  1. Codeforces 839A Arya and Bran【暴力】

    A. Arya and Bran time limit per test:1 second memory limit per test:256 megabytes input:standard inp ...

  2. Codeforces 839A Arya and Bran

    Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going ...

  3. 839A Arya and Bran

    A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. codeforce A. 2Char(水题,暴力)

    今晚发了个蛇精病,然后CF了,第一题这好难啊,然而水题一个,暴力飘过. 链接http://codeforces.com/contest/593/problem/A: 题意比较难懂吗?傻逼百度都翻译不对 ...

  5. A. Arya and Bran

    A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  6. Codeforces Round #360 (Div. 2) A. Opponents 水题

    A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...

  7. codeforces 688A A. Opponents(水题)

    题目链接: A. Opponents time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  8. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  9. ACM :漫漫上学路 -DP -水题

    CSU 1772 漫漫上学路 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

随机推荐

  1. 27. Remove Element C++移除元素

    网址:https://leetcode.com/problems/remove-element/ 双指针(广义) class Solution { public: int removeElement( ...

  2. 22. Generate Parentheses C++回溯法

    把左右括号剩余的次数记录下来,传入回溯函数. 判断是否得到结果的条件就是剩余括号数是否都为零. 注意判断左括号是否剩余时,加上left>0的判断条件!否则会memory limited erro ...

  3. Java序列化的作用和反序列化

    1.序列化是干什么的? 简单说就是为了保存在内存中的各种对象的状态(也就是实例变量,不是方法),并且可以把保存的对象状态再读出来.虽然你可以用你自己的各种各样的方法来保存object states,但 ...

  4. JDK8的ConcurrentHashMap也会造成CPU 100%

    转载:不止 JDK7 的 HashMap ,JDK8 的 ConcurrentHashMap 也会造成 CPU 100%?原因与解决~ 现象 大家可能都听过JDK7中的HashMap在多线程环境下可能 ...

  5. Python3 configparser值为多行时配置文件书写格式

    一.说明 一般而言ini配置文件键值对都是一行就完事了,但有时候我们想配置的值就是由多行组成,这里说明此时配置格式该如何书写. 二.书写格式 如果值为多行,那么在第一行外的后续所有行前加入至少一个空格 ...

  6. OWASP TOP 10 2017中文译文

    说明:owasp top 10其实有中文官方版本:本文是按着英文版进行翻译而成. 官方中文版:http://www.owasp.org.cn/owasp-project/OWASPTop102017v ...

  7. ubuntu下唤醒或休眠远程计算机

    ubuntu让我明白,没有什么完美的东西,要想完美必须付出代价.要么花时间折腾,要么花时间赚钱买系统. 人生也是一样,所以不要期待什么完美.哪有那么好的人,在合适的时间合适的地点让你遇见,还对你有感觉 ...

  8. rnnlib依赖ubuntu环境配置

    rnnlib help http://sourceforge.net/apps/mediawiki/rnnl/index.php?title=Main_Page boost: http://blog. ...

  9. Debug method

    #define DEBUG(format,...) printf("Ray.he file:"__FILE__" func:%s() line:%d, print &qu ...

  10. OOP⑺

    1.多态和instanceof 都是去买东西,但是根据我们给别人金额的不同,得到不同的结果!!!! 生活中的多态! 操作是否一致? 一致! 都是买东西! 什么不一样?? 01.消费金额不一样 02.因 ...