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.


  题目大意 有n天,在第i天Arya能够神奇地得到ai颗糖,(为了防止Bran吃糖吃多了蛀牙,所以)每天Arya最多能给Bran 8颗糖,问在最早在哪一天,Bran总共得到k颗糖。

  每天能给多少就给多少。

Code

 /**
* Codeforces
* Problem#839D
* Accepted
* Time: 171ms
* Memory: 15400k
*/
#include <bits/stdc++.h>
using namespace std; const int lim = 1e6 + ;
const int moder = 1e9 + ; int n;
int *a;
int *pow2;
int cnt[lim], counter[lim];
int f[lim];
int res = ; inline void init() {
scanf("%d", &n);
a = new int[(n + )];
pow2 = new int[(n + )];
pow2[] = ;
for(int i = ; i <= n; i++) {
scanf("%d", a + i);
counter[a[i]]++;
pow2[i] = (pow2[i - ] << ) % moder;
}
} inline void solve() {
for(int i = ; i < lim; i++)
for(int j = i; j < lim; j += i)
cnt[i] += counter[j]; for(int i = lim - ; i > ; i--) {
if(!cnt[i]) continue;
f[i] = (cnt[i] * 1LL * pow2[cnt[i] - ]) % moder;
for(int j = i << ; j < lim; j += i)
f[i] = (f[i] - f[j]) % moder;
if(f[i] < ) f[i] += moder;
res = (res + (f[i] * 1LL * i) % moder) % moder;
} printf("%d\n", res);
} int main() {
init();
solve();
return ;
}

Codeforces 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. codeforce 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. Codeforces Round #428 A. Arya and Bran【模拟】

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

  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 #428 (Div. 2) A】Arya and Bran

    [Link]: [Description] [Solution] 傻逼题 [NumberOf WA] [Reviw] [Code] #include <bits/stdc++.h> usi ...

  7. Codeforces Round #428 (Div. 2) 题解

    题目链接:http://codeforces.com/contest/839 A. Arya and Bran 题意:每天给你一点糖果,如果大于8个,就只能给8个,剩下的可以存起来,小于8个就可以全部 ...

  8. Codeforces Round #428 (Div. 2)A,B,C

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

  9. Codeforces Round #428 (Div. 2)

    终于上蓝名了,hahahahaha,虽然这场的 B 题因为脑抽了,少考虑一种情况终判错了,还是很可惜的.. B题本来过来1500个人,终判之后只剩下了200多个,真的有毒!!!! A - Arya a ...

随机推荐

  1. 分析api时去除全局异常

    invoke-static {p0}, Ljava/lang/Thread;->setDefaultUncaughtExceptionHandler(Ljava/lang/Thread$Unca ...

  2. 从零开始一起学习SLAM | SLAM有什么用?

    SLAM是 Simultaneous Localization And Mapping的 英文首字母组合,一般翻译为:同时定位与建图.同时定位与地图构建. 「同时定位与地图构建」这几个词,乍一听起来非 ...

  3. HTTP通信机制

    HTTP通信机制是在一次完整的HTTP通信过程中,Web浏览器与Web服务器之间将完成下列7个步骤:  1. 建立TCP连接 在HTTP工作开始之前,Web浏览器首先要通过网络与Web服务器建立连接, ...

  4. php背景图片上生成二维码,二维码上带logo 代码示例 (原)

    依赖库文件 phpqrcode.php (下载地址://www.jb51.net/codes/189897.html :或者在官网下载:http://phpqrcode.sourceforge.net ...

  5. mysql set

    sql server中变量要先申明后赋值: 局部变量用一个@标识,全局变量用两个@(常用的全局变量一般都是已经定义好的): 申明局部变量语法:declare @变量名 数据类型:例如:declare ...

  6. python 将文件大小转换为human readable 的大小表示

    定义了一个函数, def HRS(size):    units=('B','KB','MB','GB','TB','PB')    for i in range(len(units)-1,-1,-1 ...

  7. c++ 常用的数据结构

    set // constructing sets #include <iostream> #include <set> void checkin(std::set<int ...

  8. Linq To SQL LEFT OUTER JOIN (Left Join)

    SQL: SELECT [t0].[ProductName], [t1].[TotalPrice] AS [TotalPrice] FROM [Product] AS [t0] LEFT OUTER ...

  9. mvc未登录跳转到登录界面

    编写一个mvc控制器基类BaseController , 其继承自controller 重写其OnActionExecuting方法, 在其中检测session值,如果没有,则跳转至登录页面. 如下

  10. linux文件系统的用户和权限管理

    1. 为什么要有用户的概念? 多用户,多任务业务对系统资源的隔离产生需求 2. linux 用户的分类? 2.1. 管理员 拥有操作所有文件的权限 2.2. 普通用户 2.2.1. 普通登录用户 2. ...