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. MVC异步控制器加载一个网页的所有内容

    public void PageAsync() { AsyncManager.OutstandingOperations.Increment(); WebRequest req = WebReques ...

  2. C# 使用post的方式提交raw格式的数据,数据为json格式,多层嵌套

    原文地址:https://cnodejs.org/topic/539ff8a5c3ee0b5820938d60 raw方式使用的是纯字符串的数据上传方式,所以在POST之前,可能需要手工的把一些JSO ...

  3. spring 改变url

    server:  port: 9010  servlet:    context-path: /console

  4. 附加任务:团队作业7 Alpha冲刺

    附加任务:团队作业7 Alpha冲刺 附加任务要求参考东北师范大学陈志勇老师博客:https://edu.cnblogs.com/campus/nenu/2016SE_NENU/homework/19 ...

  5. lvm磁盘分区

    初始分区情况见下: 创建lvm类型磁盘 创建卷pv 添加pv到vg中,vg名vgroup0 创建lv lvcreate -L 2g -n zookeeper vgroup0 在vg vgroup0中创 ...

  6. CGLIB代理基础

    本文意在讲解CGLIB的基础使用及基本原理. 一.CGLIB的基本原理: 依赖ASM字节码工具,通过动态生成实现接口或继承类的类字节码,实现动态代理. 针对接口,生成实现接口的类,即implement ...

  7. Session和Cookie的理解

    原文地址:https://juejin.im/post/5aede266f265da0ba266e0ef

  8. centos7安装zabbix3.5

    安装centos7 自带MariaDB数据库(或者安装mysql) yum -y install mariadb-server mariadb-devel systemctlstartmariadb. ...

  9. python 读取文件第一列 空格隔开的数据

    file=open('6230hand.log','r') result=list() for c in file.readlines(): c_array=c.split(" " ...

  10. 使用Python计算IP、TCP、UDP校验和

    IP数据报的校验: IP数据报只需要对数据头进行校验,步骤如下: 将接收到的数据的checksum字段设置为0 把需要校验的字段的所有位划分为16位(2字节)的字 把所有16位的字相加,如果遇到进位, ...