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

Example
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<cstdio>
int a[105];
int main()
{int n,k,i,cnt=0,num=0;scanf("%d%d",&n,&k);{for(i=0;i<n;i++)scanf("%d",&a[i]);for(i=0;i<n;i++){cnt++;num=num+a[i];if(num>8){k=k-8;num=num-8;}else{k=k-num;num=0;}if(k<=0)break;}if(i==n)cnt=-1;printf("%d\n",cnt);}return 0;
}

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

  2. Codeforces #839A: Arya and Bran 题解

    这题直接模拟就好了 将这天能得到的糖果加进计数器,如果当天多于8个就给八个,否则给光 n天后,看能否给出不少于k个的糖果 #include <cstdio> #include <io ...

  3. CodeForces 839A Arya and Bran

    唯一要注意的是前一天剩下的可以存起来以后发 #include<iostream> #include<cstdio> #include<cstdlib> #inclu ...

  4. CF 839A - Arya and Bran(水)

    Discription 给定n天,每天有a[i]个蛋糕.小明一共需要k个蛋糕,每天给小明的蛋糕数量<=8,如果今天给了小明8个蛋糕后有剩余,可以将剩余的蛋糕积攒到明天,以此类推,问小明最少几天能 ...

  5. Codeforces Round #428 (Div. 2):A. Arya and Bran

    题目: Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is go ...

  6. Arya and Bran Game of the Rows Multiple Clocks

    题目一:Arya and Bran 错解: #include<cstdio> int main() {int n,k,candy;int left = 0,day = 0,toGive = ...

  7. codeforces 839A

    水题  题意 分糖果  每次最多8个  多出来的可以遗留到下一天 注意下一天少于8个要清0: 代码: #include<bits/stdc++.h> using namespace std ...

  8. Codeforces 题目合集+分类+代码 【Updating...】【361 in total】

    961A - Tetris                                                模拟                                      ...

  9. python运行mcmc为何老出错_python中mcmc方法的实现

    MCMC方法在贝叶斯统计中运用很多,MIT发布的EMCEE是实现的比较好的.介绍页面在下面.源代码中examples里的代码可以帮助理解各种功能,特别是line.py 列出了最小二乘法,最大似然法和M ...

最新文章

  1. BlockChain:BlockChain周边概念详解+个人理解
  2. IOS 关于ipad iphone5s崩溃 解决
  3. mysql acid_Mysql中ACID的原理
  4. 如何免费注册Coursera课程
  5. python thread 共享数据
  6. 李彦宏说吃着火锅唱着歌,奔驰你却要我命!
  7. centos 安装 Pip 的方法总结
  8. Visual Studio 2010 使用Windows Media Player控件实现播放音乐视频
  9. 作为一名软件测试工程师,需要具备哪些能力?
  10. PhotoShop 保存 8 bit 位图(Bmp)的方法【记录备忘】
  11. 华为scp快充协议详解_华为SCP快充技术曝光:支持“电荷泵”技术,最高可达20W...
  12. Python脚本实现WIFI网络的扫描、连接和断开
  13. linux下安装python3报错_Linux中安装python3
  14. docker-compose 搭建 Rap2 接口管理平台
  15. 谭浩强c语言不讲位运算呢,谭浩强C语言教程第十二章-位运算.doc
  16. 文档级机器翻译综述:A Survey on Document-level Machine Translation: Methods and Evaluation
  17. 对象存储OSS之ossbrowser的使用
  18. 【已解决】rgss202e.dll与电脑不兼容怎么办?
  19. 《信号与系统》笔记·第一章:信号与系统
  20. 【愚公系列】2021年12月 网络工程-PKI

热门文章

  1. 垃圾分类网站 web前端 + java后端
  2. 读取EXCEL文件数据,再调用第三方接口,将第三方数据重新写入到EXCEL文件
  3. 0x000001b8指令引用的0x000001b8内存该内存不能为read
  4. flutter 自定义进度条progress
  5. 芝诺数解|「十」渝味之城,愉味无穷——重庆十一旅游数据分析报告
  6. 解决win10 VirtualBox不能打开一个新任务
  7. 如何把网页设置成桌面快捷方式
  8. CSDN文章 无法通过百度搜索,怎么办?
  9. Knockout绑定语法
  10. matlab premnmx归一化函数的使用 1、premnmx 预处理数据使数据的最小值和最大值分别为-1和1. [PN,minp,maxp,TN,mint,maxt] = premnmx(P,T)