839A Arya and Bran
1 second
256 megabytes
standard input
standard output
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.
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 3
1 2
2
3 17
10 10 10
3
1 9
10
-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.
题意:
每天给你一点糖果,如果大于8个,就只能给8个,剩下的可以存起来,小于8个就可以全部给完
#include <iostream>
using namespace std; int main(){
int n, k;
cin >> n >> k;
int a[];
for(int i = ; i < n; i++){
cin >> a[i];
}
int count = ;
for(int i = ; i < n; i++){
if(a[i] < ){
k -= a[i];
}else{
if(a[i] == ){
k -= ;
}else{
k -= ;
a[i + ] += a[i] - ;
}
}
count++;
if(k <= )
break;
}
if(k >){
cout << - << endl;
return ;
}
cout << count << endl;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin >> n >> m;
int ans = ;
for(int i = ;i <= n;i++)
{
int x;
cin >> x;
// 模拟过程
ans += x;
// ans 当前有多少糖果
m -= min(ans,);
ans -= min(ans,);
if(m <= )
return !printf("%d\n",i);
}
return !printf("-1\n");
}
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:standard inp ...
- Codeforces 839A Arya and Bran
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going ...
- codeforce 839A Arya and Bran(水题)
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going ...
- Codeforces Round #428 A. Arya and Bran【模拟】
A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- A. Arya and Bran
A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- 【Codeforces Round #428 (Div. 2) A】Arya and Bran
[Link]: [Description] [Solution] 傻逼题 [NumberOf WA] [Reviw] [Code] #include <bits/stdc++.h> usi ...
- Codeforces Round #428 (Div. 2) 题解
题目链接:http://codeforces.com/contest/839 A. Arya and Bran 题意:每天给你一点糖果,如果大于8个,就只能给8个,剩下的可以存起来,小于8个就可以全部 ...
- Codeforces Round #428 (Div. 2)A,B,C
A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #428 (Div. 2)
终于上蓝名了,hahahahaha,虽然这场的 B 题因为脑抽了,少考虑一种情况终判错了,还是很可惜的.. B题本来过来1500个人,终判之后只剩下了200多个,真的有毒!!!! A - Arya a ...
随机推荐
- js基础-数组及数据类型
数组也是引用类型 构造函数创建数组 Object 构造函数类型(所有类型基类) Array 构造函数类型 求幂运算符 ** 2**32-1 数组容量最大 arry.length 如果减小len ...
- 内核 platform_get_resource() 函数解析
struct resource *platform_get_resource(struct platform_device *dev, unsigned int type, un ...
- 微擎框架下拉分页(使用js模板引擎)
1.需要分页的页面,引入一下文件 <script language="javascript" src="\addons\{$_GPC['m']}\template\ ...
- ubuntu下zaibbix3.2报警搭建
1.安装sudo apt install sendmail 2.测试发送邮件: echo "正文!" | mail -s 标题 XXX@qq.com 3.成功后继续安装邮件服务器. ...
- 'basetsd.h': No such file or directory
By Select the Windows 8.1 SDK During install. Download visualcppbuildtools_full.exe from below websi ...
- keras初探
1.对网络的理解: 2.怎样训练,输入已经数据,经过训练,输入测试数据,得到相似数据 3.RNNs 循环神经网络
- maven(二)基于intellij idea搭建ssm的maven项目结构
项目配置文件整合步骤 1.这里使用maven来引入项目所需要的jar包,所以也就不需要手动来管理jar包了. pom.xml 配置模板如下: <project xmlns="http: ...
- Java中this和super的用法和区别
super(参数):调用父类中的某一个构造函数(应该为构造函数中的第一条语句). this(参数):调用本类中另一种形式的构造函数(应该为构造函数中的第一条语句). this的实例: package ...
- android TextView SetText卡顿原因
[android TextView SetText卡顿原因] 不要用wrap_content即可. 参考:http://blog.csdn.net/self_study/article/details ...
- sqlmap自动注入
基于python2.7开发 git clone https://github.com/sqlmapproject/sqlmap.git sqlmap-dev