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 ...
随机推荐
- 利用monkeyrunner、python脚本来做多设备多apk适配ui界面截屏的自动化测试
http://www.cnblogs.com/youxilua/archive/2011/11/25/2262715.html
- 学JS的心路历程-函式(六)其余参数及预设参数
今天我们要来介绍ES6新增的其余参数及预设参数! 其余参数rest parameter …numbers可以让我们表示不确定数量的参数,并将其视为一个数组: function getVal(…numb ...
- anchor_generator.proto:11:3: Expected "required", "optio nal", or "repeated"
转自:https://github.com/tensorflow/models/issues/1834 When I use the commond " protoc object_dete ...
- centos7.5下yum 安装mariadb数据库
前言 mariadb 和mysql就像亲兄弟的关系,各种语法.驱动啥的,在mysql上能上的,在mariadb上基本都可以直接使用.更多的细节在此不多说. 1.删除旧版本 centos7下默认安装有m ...
- SQL Server和MySQL数据库
导读:接下来的网上商城的项目,需要用到MySQL数据库了.这个对于我来说,是一个新接触的东西,按照惯例,在刚开始学习一个东西的时候,先从宏观上去了解它.本篇博客,先介绍SQL Server的基本内容, ...
- polyfill
[polyfill] 在JavaScript的世界里,有两个词经常被提到,shim和polyfill.它们指的都是什么,又有什么区别? 一个shim是一个库,它将一个新的API引入到一个旧的环境中,而 ...
- spring分页
1.Brand 商品品牌类 public class Brand { private Integer id; private String name; private String descripti ...
- java并发:CopyOnWriteArrayList简单理解
Java集合的快速失败机制 “fail-fast” "fail-fast"是java集合的一种错误检测机制,当多个线程对集合进行结构上的改变的操作时,有可能会产生 fail-fas ...
- 最小生成树算法(krustra+prime)
给你一个图,求让图连通的边权和最小值 krustra算法是基于加边法,将所有边权排序,每次加一条边,将两个点放在同一个集合中.如果新加的点不在同一个集合中,就合并(并查集) 涉及到排序,可以用结构体存 ...
- AVL树与红黑树(R-B树)的区别与联系
AVL树(http://baike.baidu.com/view/593144.htm?fr=aladdin),又称(严格)高度平衡的二叉搜索树.其他的平衡树还有:红黑树.Treap.伸展树.SBT. ...