Codeforces Round #428 A. 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 aicandies in a box, that is given by the Many-Faced God. Every day she can give Bran at most8 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 beforethe 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 kcandies 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 8candies per day and she must give him the candies within 1 day.
【题意】:给你n,k。1~n天发给他糖果,超过8给8,剩下的可以存,不超过8给当前的。求最少给到k的天数。
【分析】:模拟
【代码】:
#include <bits/stdc++.h> using namespace std;
#define LL long long
const int INF = 0x3f3f3f3f;
#define mod 10000007
#define mem(a,b) memset(a,b,sizeof a) int main()
{
int n,m;
int a[];
while(~scanf("%d%d",&n,&m))
{
int sum=;
int ans=;
for(int i=; i<n; i++)
{
scanf("%d",&a[i]);
}
int flag=-;
for(int i=; i<n; i++)
{
ans+=a[i];
if(ans>=)
sum+=,ans-=;
else
sum+=ans,ans=;
if(sum>=m)
{
flag=i+;
break;
}
}
printf("%d\n",flag);
}
return ;
}
Codeforces Round #428 A. Arya and Bran【模拟】的更多相关文章
- CodeForces 839C - Journey 	|   Codeforces Round #428 (Div. 2)
		
起初误以为到每个叶子的概率一样于是.... /* CodeForces 839C - Journey [ DFS,期望 ] | Codeforces Round #428 (Div. 2) */ #i ...
 - CodeForces 839D - Winter is here  | Codeforces Round #428 (Div. 2)
		
赛后听 Forever97 讲的思路,强的一匹- - /* CodeForces 839D - Winter is here [ 数论,容斥 ] | Codeforces Round #428 (Di ...
 - CodeForces 839B - Game of the Rows  | Codeforces Round #428 (Div. 2)
		
血崩- - /* CodeForces 839B - Game of the Rows [ 贪心,分类讨论] | Codeforces Round #428 (Div. 2) 注意 2 7 2 2 2 ...
 - Codeforces Round #428 (Div. 2) 题解
		
题目链接:http://codeforces.com/contest/839 A. Arya and Bran 题意:每天给你一点糖果,如果大于8个,就只能给8个,剩下的可以存起来,小于8个就可以全部 ...
 - Codeforces Round #428 (Div. 2)
		
终于上蓝名了,hahahahaha,虽然这场的 B 题因为脑抽了,少考虑一种情况终判错了,还是很可惜的.. B题本来过来1500个人,终判之后只剩下了200多个,真的有毒!!!! A - Arya a ...
 - 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) A】Arya and Bran
		
[Link]: [Description] [Solution] 傻逼题 [NumberOf WA] [Reviw] [Code] #include <bits/stdc++.h> usi ...
 - Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)
		
A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
 - Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】
		
A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
 
随机推荐
- 《Cracking the Coding Interview》——第13章:C和C++——题目7
			
2014-04-25 20:18 题目:给定一个Node结构体,其中包含数据成员和两个Node*指针指向其他两个Node结构(还不如直接说这是个图呢).给你一个Node指针作为参数,请做一份深拷贝作为 ...
 - 《Cracking the Coding Interview》——第7章:数学和概率论——题目7
			
2014-03-20 02:29 题目:将质因数只有3, 5, 7的正整数从小到大排列,找出其中第K个. 解法:用三个iterator指向3, 5, 7,每次将对应位置的数分别乘以3, 5, 7,取三 ...
 - win7 64位如何共享XP上的打印机?
			
这个问题看似很简单,但是一旦你遇到了,就会发觉不是想象的那么简单. 除了网上能搜到的一些设置之外,这里还有几个诀窍: 1.首先你必须准备你的打印机的64位驱动程序 2.你在win7上必须采用添加本地打 ...
 - 【转载】法线贴图Nomal mapping 原理
			
法线贴图多用在CG动画的渲染以及游戏画面的制作上,将具有高细节的模型通过映射烘焙出法线贴图,贴在低端模型的法线贴图通道上,使之拥有法线贴图的渲染效果,却可以大大降低渲染时需要的面数和计算内容,从而达到 ...
 - Python全栈工程师 (exercises)
			
# 1:给定一个数,判断他是正数,负数,还是0 a = int(input("请输入一该个整数")) if a == 0: print(a, "是0") eli ...
 - NodeJS05
			
商品分类模块 分类model const mongoose = require('mongoose') const schema = new mongoose.Schema({ name: { typ ...
 - Scrapy 学习笔记(一)数据提取
			
Scrapy 中常用的数据提取方式有三种:Css 选择器.XPath.正则表达式. Css 选择器 Web 中的 Css 选择器,本来是用于实现在特定 DOM 元素上应用花括号内的样式这样一个功能的. ...
 - HttpRuntime.Cache再学习
			
摘抄: 可以看到:读缓存,其实是在调用Get方法,而写缓存则是在调用Insert方法的最简单的那个重载版本. 注意了:Add方法也可以将一个对象放入缓存,这个方法有7个参数,而Insert也有一个签名 ...
 - J2EE的十三个技术——EJB之实体Bean
			
概述: 实体Bean与会话Bean不同,实体Bean是持久的,即使应用程序结束,它仍然存在.它允许共享访问,具有主键. 组成: 1)本地(Local)接口 本地访问EJB,只有在EJB与客户在同一个应 ...
 - BOZJ 2045:疯狂的馒头(并查集)
			
题目大意:有n个馒头排成一排,初始时颜色为0,进行m次染色,第i次将(i*p+q)mod n到(i*q+p)mod n的馒头全部染成颜色i,求最后所有馒头颜色.n<=10^6 m<=10^ ...