Discription

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

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

如果在n天内小明得不到足够的蛋糕,输出-1

Examples

input
2 3
1 2
output
2
input
3 17
10 10 10
output
3
input
1 9
10
output
-1

Code

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>using namespace std;int a[111];int main()
{// freopen("in.txt", "r", stdin);int n, k;while (~scanf("%d%d", &n, &k)){for (int i = 0; i < n; i++)scanf("%d", &a[i]);int ans = -1;for (int i = 0; i < n; i++){int t = min(a[i], 8);a[i + 1] += (a[i] - t);k -= t;if (k <= 0){ans = i;break;}}if (ans == -1)printf("-1\n");elseprintf("%d\n", ans + 1);}return 0;
}

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

  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. cf 11A Increasing Sequence(水,)

    题意: A sequence a0, a1, ..., at - 1 is called increasing if ai - 1 < ai for each i: 0 < i <  ...

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

    961A - Tetris                                                模拟                                      ...

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

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

  9. 7月1日 cf总结

    7月1日  cf总结 A题:水题,题意看半天,30分钟才A. #include<iostream> #include<cstdio> #include<cstring&g ...

最新文章

  1. Android — 长按ListView 利用上下文菜单(ActionMode) 进行批量事件处理
  2. ajax在Xss中的利用,XSS高级利用
  3. Java中main函数只能调用同类中的静态方法?
  4. 计算机系毕业生自我评价,计算机系应届毕业生自我评价范文
  5. 点云的密度 曝光时间_200倍的提速!华人博士生提出大场景三维点云语义分割新框架...
  6. 垂直居中小记 line-height table vertical-align:middle
  7. 最详细Python批量字典暴力破解zip密码
  8. 国内外中英文版一元购网站开发案例源码
  9. omnigraffle所有模板免费下载网站
  10. Axure制作微信APP原型(一)四大模块:消息、通讯录、发现、我
  11. Python实现生成西瓜数据集的Excel文件
  12. 单本振与双本振台标文件的区别在哪里?
  13. JSON字符串中带有反斜杠
  14. Linux下压缩与解压缩
  15. win32 015使用菜单和加速键
  16. sqlite3数据库的使用
  17. adb操作提示Read-only file system问题
  18. 如何写一个自动重复发消息的脚本,聪哥手把手教你(适配任何可发消息的app),亲测有效
  19. matlab 电压矢量开关,解析电压空间矢量研究及Matlab仿真
  20. 国内企业怎么做好海外市场营销? 海外市场营销推广的全过程

热门文章

  1. 自主研发项目三之微信上门洗车系统
  2. PADS Logic中单个器件的PCB封装应该怎么处理呢?
  3. Android实战场景 - 限制EditText仅支持输入数字、英文、汉字,禁止输入表情等特殊符号
  4. 鸡米过河matlab程序,农夫,狐狸,鸡,米的程序
  5. stm32单片机屏幕一直闪_基于STM32单片机实现屏幕休眠后OLED屏幕滚动效果
  6. 电脑常见错误代码解析
  7. 2022一建四色笔记
  8. 创客教育中的空间设计实物原理
  9. 计算机应用基础问卷答题,中职计算机应用基础课程教学改革与实践
  10. 一个老软件测试工程师的日志