CF 839A
来源:互联网 发布:机床的重要性 知乎 编辑:程序博客网 时间:2024/06/09 16:21
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"); else printf("%d\n", ans + 1); } return 0;}
阅读全文
0 0
- CF 839A
- CF 2A Winner
- CF 128A Statues
- <cf>A. Exams
- CF 109A
- CF 111A
- CF 4A Watermelon
- CF 237A (Cash)
- CF 6 A - Triangle
- CF:96A.Football
- CF:208A. Dubstep
- CF:41A. Translation
- CF:59A. Word
- CF:43A. Football
- CF:78A. Haiku
- CF:A. Flipping Game
- CF 148 div1 A
- CF 127 div1 A
- JavaSe-注解及动态代理小结
- 新内核模块引用其他模块中的全局变量,编译报错处理方式
- 大数据竞赛平台——Kaggle 入门
- java中中文输入法与英文输入法符号的差别
- Python循环学习之最易错的语法详解
- CF 839A
- 在Jekyll博客添加评论系统:gitment篇
- IoC容器
- 地牢逃脱 (BFS)
- vue2.0
- android 自定义View之将字体绘制在Rect中间
- LeetCode: 65.Valid Number
- HDU 1159 Common Subsequence(最长公共子序列(LCS) 动态规划(DP))
- 医院刚刚严重发声,情况紧急!全民必看!