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 ;
}

最新文章

  1. .NET跨平台之旅:数据库连接字符串写法引发的问题
  2. go程序注册为windows服务
  3. Javascript - Arraylike的7种实现
  4. mysql数据库优化小结
  5. C# 点绕某点旋转某角度
  6. iOS 可延展视图(点击前显示部分文字,点击后显示全部)
  7. Ogre分层渲染 (转)
  8. Linux怪哉ntfs
  9. Delphi 缩放图像代码 - 支持PNG透明通道(利用了Windows的windowscodecs.dll)
  10. Tomcat学习笔记 - 错误日志 - NetBeans配置tomcat出错情况总结 -- 部署错误: 启动 Tomcat 失败。-- &#39;127.0.0.1&#39; 不是内部或外部命令,也不是可运行的程序
  11. 04-UIKit(UINavigationController、NSAttributeString、UIImageView)
  12. ThreadLocal 遇上线程池的问题及解决办法
  13. 深入理解android6.0 RunTime Permisstion
  14. Web前端新手想提升自身岗位竞争力,需做好这3件事!
  15. Redis笔记(四):Redis事务支持
  16. 如何使用C#程序给PDF文件添加编辑域
  17. bzoj5123 [Lydsy12月赛]线段树的匹配
  18. python学习笔记(十三)之lambda表达式
  19. 关于/proc/进程idpid/fd ,根据fd来查找连接
  20. 什么是“QQ登录OAuth2.0”

热门文章

  1. (一)从设计的角度来看ADT(Java)
  2. 创建属性Attribute
  3. eclipse初学者的使用
  4. php-fpm占用cpu和内存过高100% 解决办法
  5. cpu占用过高排查
  6. Python isspace() 方法检测字符串是否只由空格组成。
  7. php composer 使用 以及 psr0和psr4的真正区别
  8. 外部调用mvc的api方法时,如何解决跨域请求问题?
  9. VMware 安装 centos,自定义分区
  10. Win10系列:JavaScript获取文件和文件夹列表