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比一下大小。

#include<iostream>
#include<cstdio>
using namespace std;
int n,m,sum,ans=;
int main()
{
int i,j;
scanf("%d%d",&n,&m);
for(i=;i<=n;i++)
{
scanf("%d",&j);
sum+=j;
m-=min(sum,);
sum=sum-min(sum,);
if(m<=)ans=min(ans,i);
}
if(ans!=)printf("%d\n",ans);
else printf("-1\n");
return ;
}

A. 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. 839A Arya and Bran

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

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

  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. UOJ_407_【IOI2018】狼人

    http://uoj.ac/problem/407 分析: 分别建立最小/最大kruskal重构树. 每次询问给出的两个点能走到的部分分别对应两棵树\(dfs\)序的一段区间. 转化成判断矩形中是否有 ...

  2. poj2392磊石头——排序后背包

    题目: 首先按限制高度从小到大排序,不会影响可行解,而不排序可能卡掉正确的情况: 用%2滚动数组时一定注意每次复制上一种情况,因为这个WA了好几次. 代码如下: #include<iostrea ...

  3. AI-Info-Micron-Insight:Micron 美光的技术帮助 CERN 解开宇宙奥秘

    ylbtech-AI-Info-Micron-Insight:Micron 美光的技术帮助 CERN 解开宇宙奥秘 1.返回顶部 1. Micron 美光的技术帮助 CERN 解开宇宙奥秘 大约 14 ...

  4. java-并发-进程和线程

    浏览以下内容前,请点击并阅读 声明 软件的并发是指同时做多件事情,java平台一开始就支持并发编程,java编程语言以及类库含有对并发最基本的支持,从5.0版本开始,java平台开始包含一些高并发的A ...

  5. Linux 运维面试问题总结

    Linux 运维面试问题总结 1.详细描述mysql主从复制的方式?(类似跟DRBD高可用的协议类型) 答: (1)同步复制(C协议:sync):只有在本地和远程磁盘都确定写入已完成时,主节点才会认为 ...

  6. Spring boot 学习 五:domain的定义

    一 public class City implements Serializable 实现了Sericalizable接口,只是一种标志.表示可以被序列化. java的ObjectOutputStr ...

  7. Hibernate区分不同对象的方法

    1.关系数据库按主键区分不同记录. create table CUSTOMERS (ID int promary key not null, NAME varchar(15));     insert ...

  8. linux c二级指针的内存分配和使用

    #include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h> ...

  9. Solr 6.7学习笔记(04)-- suggester 遇到的问题

    遇到的一些问题: 在前面的Suggest配置完后,我在 “/select” 这个 <requestHandler>里面加上了highlight的配置,可是当我在搜索框里输入字符时,竟然报如 ...

  10. codeforces757F Team Rocket Rises Again【支配树+倍增+拓扑+spfa】

    先跑spfa求出最短路构成的DAG,然后在DAG上跑出支配树dfs出size取max即可 关于支配树,因为是DAG,支配点就是入点在支配树上的lca,所以一边拓扑一边预处理倍增,然后用倍增求lca # ...