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

    Redis 可用于内存存储,也可以基于持久化存储 Key-Value的形式存储. Redis的数据结构 1.字符串(string) 2.字符串列表(lists) 3.字符串集合(sets) 4.有序字 ...

  2. Html----表单元素

    表单元素:用于客户端和服务端进行信息交互的通道 <form></form>:所有的表单元素都应该放在里面 文本输入框: <input type="text&qu ...

  3. linus jsch文件下载

    package com.osplat.util;import java.io.File;import java.io.FileNotFoundException;import java.io.File ...

  4. 进制转换&数据类型(1)

    一: 进制转换 在计算机中, 数据都是以0和1来表示的 进制: 进位制 十进制: 数字由0~9这10个数字来表示, 逢10进1位 0 1 2 3 4 5 6 7 8 9 10 二进制: 数字由0和1这 ...

  5. SMB扫描

    server message block协议,Windows特有的一个协议,实现较复杂,windows应用最广的一个协议,也是安全问题最多的问题,smb协议windows默认开发,用于文件共享. sm ...

  6. mongodb-参考其他

    MongoDB教程 http://www.runoob.com/mongodb/mongodb-window-install.html

  7. vue生命周期简介

    vue生命周期简介 生命周期的钩子 LifeCycle hooks 上面已经能够清晰的看到vue2.0都包含了哪些生命周期的钩子函数~~ 那么 执行顺序以及什么时候执行,我们上代码来看~~~ 生命周期 ...

  8. Jenkins安装部署(一)

    环境准备 CentOS Linux release 7.4 1.IP:192.168.43.129 2.路径:/mnt 3.jdk版本:jdk1.8.0 4.tomcat版本:tomcat-8.5 5 ...

  9. TOJ 2130: Permutation Recovery(思维+vector的使用)

    传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=2130 时间限制(普通/Java): ...

  10. TOJ 2755 国际象棋(搜索)

    传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=2755 思路:对起点到终点进行广搜, ...