Codeforces Round #428 (Div. 2) A. Arya and Bran
来源:互联网 发布:js如何定义集合 编辑:程序博客网 时间:2024/05/16 12:13
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. Print -1 if she can't give him k candies during n given days.
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).
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.
2 31 2
2
3 1710 10 10
3
1 910
-1
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.
#include <iostream>#include <iomanip>#include <algorithm>#include <cstdio>#include <cstring>#include <queue>#include <deque>#include <string>#include <cmath>#include <vector>#include <utility>#include <set>#include <map>#include <sstream>#include <climits>//#pragma comment(linker, "/STACK:1024000000,1024000000")#define pi acos(-1.0)#define INF 2147483647using namespace std;typedef long long ll;typedef pair<int,int > P;int k,n,i,j;int s[105];int main(){ scanf("%d%d",&n,&k); for(i=0; i<n; i++) { scanf("%d",&s[i]); } int num=0; int res=0; for(i=0; i<n; i++) { if(s[i]>=8) { num+=8; res+=s[i]-8; } else { if(s[i]+res>=8) { num+=8; res-=(8-s[i]); } else { num+=s[i]+res; res=0; } } if(num>=k) { printf("%d\n",i+1); return 0; } } if(num<k) printf("-1\n"); return 0;}
- Codeforces Round #428 (Div. 2) A. Arya and Bran
- Codeforces Round #428 (Div. 2):A. Arya and Bran
- Codeforces Round #428 (Div. 2) A. Arya and Bran
- Codeforces Round #428 (Div. 2) A. Arya and Bran
- Codeforces Round #428 (Div. 2) A. Arya and Bran
- Codeforces Round #428 (Div. 2) && 839A A. Arya and Bran
- Codeforces Round #428 (Div. 2) A. Arya and Bran(【贪心】)
- Codeforces 839A Arya and Bran (模拟)
- Codeforces #839A: Arya and Bran 题解
- Codeforces 839A-Arya and Bran
- codeforces 839A Arya and Bran
- codeforces 839A 之 Arya and Bran
- Codeforces--839A--Arya and Bran
- A. Arya and Bran
- A. Arya and Bran
- CF428 (2) A. Arya and Bran
- Codeforces839A Arya and Bran
- CodeForces839A Arya and Bran
- C语言--字符串基本操作
- 适用中大型公司分部门分项目的精确的SVN文档和代码控制系统
- uva11354
- XML文档_SAX解析
- zxing 二维码生成深度定制
- Codeforces Round #428 (Div. 2) A. Arya and Bran
- HDU
- 并查集(Union Find)简介
- 《Unity3D》用PlayerPres来保存读取自定义类型数组
- docker中容器的四种网络模式详解
- 大型定时任务数据结构HashedWheelTimer
- 0.9999999999999999999999 == 1?
- GoldenGate Integrated Capture Mode介绍及配置方法
- redis 4 搭建集群