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

题意:

每天给你一点糖果,如果大于8个,就只能给8个,剩下的可以存起来,小于8个就可以全部给完

 #include <iostream>
using namespace std; int main(){
int n, k;
cin >> n >> k;
int a[];
for(int i = ; i < n; i++){
cin >> a[i];
}
int count = ;
for(int i = ; i < n; i++){
if(a[i] < ){
k -= a[i];
}else{
if(a[i] == ){
k -= ;
}else{
k -= ;
a[i + ] += a[i] - ;
}
}
count++;
if(k <= )
break;
}
if(k >){
cout << - << endl;
return ;
}
cout << count << endl;
}
 #include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin >> n >> m;
int ans = ;
for(int i = ;i <= n;i++)
{
int x;
cin >> x;
// 模拟过程
ans += x;
// ans 当前有多少糖果
m -= min(ans,);
ans -= min(ans,);
if(m <= )
return !printf("%d\n",i);
}
return !printf("-1\n");
}

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

  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. 23种经典设计模式UML类图汇总

    在这里23种经典设计模式UML类图汇总       创建型模式 1.FACTORY—追MM少不了请吃饭了,麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西,虽然口味有所不同,但不管你带MM去麦当劳或肯德基 ...

  2. jstl-日期格式化-jsp页面需引入fmt标签

    jsp页面需引入fmt标签: <taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"> ...

  3. java fastJson

    // 大区的数据 String cityList = "[{'title':'华北','value':'1','children':[{'title':'山东','value':'1.1', ...

  4. c#中连接数据库

    配置文件web.config: <connectionStrings> <add name="eport" connectionString="Data ...

  5. Beef的使用

    应用普遍转移到B/S架构,浏览器成为统一客户端程序 通过注入JS脚本,利用浏览器攻击其他网站 ruby编写 攻击手段 利用网站XSS漏洞实现攻击 诱使客户端访问含有hook的伪造站点 结合中间人攻击注 ...

  6. python return 及lambda函数

    return有两个作用: 1.用来返回函数的运行结果,或者调用另外一个函数.比如max()函数 >>> def fun(a,b): #返回函数结果. return max(a,b) ...

  7. linux按键映射

    .Xmodmap keycode = Mode_switch keysym k = k K Left keysym j = j J Down keysym l = l L Right keysym h ...

  8. Vue组成和第3方插件

    vue全家桶的成员是:vue-cli,vuex,vue-router,vue-axios(vue2.0). 第三方插件:vue-scroller,vue-lazyload,vue-awesome-sw ...

  9. pandas中series和dataframe之间的区别

    series结构有索引,和列名组成,如果没有,那么程序会自动赋名为None series的索引名具有唯一性,索引可以数字和字符,系统会自动将他们转化为一个类型object. dataframe由索引和 ...

  10. leecode 937 Reorder Log Files (模拟)

    传送门:点我 You have an array of logs.  Each log is a space delimited string of words. For each log, the ...