CF 839A - Arya and Bran(水)
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(水)相关推荐
- codeforces 839A Arya and Bran
点击打开链接 A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces #839A: Arya and Bran 题解
这题直接模拟就好了 将这天能得到的糖果加进计数器,如果当天多于8个就给八个,否则给光 n天后,看能否给出不少于k个的糖果 #include <cstdio> #include <io ...
- CodeForces 839A Arya and Bran
唯一要注意的是前一天剩下的可以存起来以后发 #include<iostream> #include<cstdio> #include<cstdlib> #inclu ...
- 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 = ...
- 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 ...
- cf 11A Increasing Sequence(水,)
题意: A sequence a0, a1, ..., at - 1 is called increasing if ai - 1 < ai for each i: 0 < i < ...
- Codeforces 题目合集+分类+代码 【Updating...】【361 in total】
961A - Tetris 模拟 ...
- python运行mcmc为何老出错_python中mcmc方法的实现
MCMC方法在贝叶斯统计中运用很多,MIT发布的EMCEE是实现的比较好的.介绍页面在下面.源代码中examples里的代码可以帮助理解各种功能,特别是line.py 列出了最小二乘法,最大似然法和M ...
- 7月1日 cf总结
7月1日 cf总结 A题:水题,题意看半天,30分钟才A. #include<iostream> #include<cstdio> #include<cstring&g ...
最新文章
- Android — 长按ListView 利用上下文菜单(ActionMode) 进行批量事件处理
- ajax在Xss中的利用,XSS高级利用
- Java中main函数只能调用同类中的静态方法?
- 计算机系毕业生自我评价,计算机系应届毕业生自我评价范文
- 点云的密度 曝光时间_200倍的提速!华人博士生提出大场景三维点云语义分割新框架...
- 垂直居中小记 line-height table vertical-align:middle
- 最详细Python批量字典暴力破解zip密码
- 国内外中英文版一元购网站开发案例源码
- omnigraffle所有模板免费下载网站
- Axure制作微信APP原型(一)四大模块:消息、通讯录、发现、我
- Python实现生成西瓜数据集的Excel文件
- 单本振与双本振台标文件的区别在哪里?
- JSON字符串中带有反斜杠
- Linux下压缩与解压缩
- win32 015使用菜单和加速键
- sqlite3数据库的使用
- adb操作提示Read-only file system问题
- 如何写一个自动重复发消息的脚本,聪哥手把手教你(适配任何可发消息的app),亲测有效
- matlab 电压矢量开关,解析电压空间矢量研究及Matlab仿真
- 国内企业怎么做好海外市场营销? 海外市场营销推广的全过程