codeforces 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.
模拟这个过程。
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{int n,k,a[110];int i;scanf("%d%d",&n,&k);for(i=1;i<=n;i++)scanf("%d",&a[i]);int now=0,g=0;bool flag=false;for(i=1;i<=n;i++){now+=a[i];if(now>=8){now-=8;g+=8;}else{g+=now;now=0;}if(g>=k){flag=true;break;}}if(flag)printf("%d\n",i);elseprintf("-1\n");return 0;
}
codeforces 839A Arya and Bran相关推荐
- Codeforces #839A: Arya and Bran 题解
这题直接模拟就好了 将这天能得到的糖果加进计数器,如果当天多于8个就给八个,否则给光 n天后,看能否给出不少于k个的糖果 #include <cstdio> #include <io ...
- CodeForces 839A Arya and Bran
唯一要注意的是前一天剩下的可以存起来以后发 #include<iostream> #include<cstdio> #include<cstdlib> #inclu ...
- CF 839A - Arya and Bran(水)
Discription 给定n天,每天有a[i]个蛋糕.小明一共需要k个蛋糕,每天给小明的蛋糕数量<=8,如果今天给了小明8个蛋糕后有剩余,可以将剩余的蛋糕积攒到明天,以此类推,问小明最少几天能 ...
- Codeforces Round #428 (Div. 2):A. Arya and Bran
题目: Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is go ...
- Arya and Bran Game of the Rows Multiple Clocks
题目一:Arya and Bran 错解: #include<cstdio> int main() {int n,k,candy;int left = 0,day = 0,toGive = ...
- codeforces 839A
水题 题意 分糖果 每次最多8个 多出来的可以遗留到下一天 注意下一天少于8个要清0: 代码: #include<bits/stdc++.h> using namespace std ...
- Codeforces 题目合集+分类+代码 【Updating...】【361 in total】
961A - Tetris 模拟 ...
- python运行mcmc为何老出错_python中mcmc方法的实现
MCMC方法在贝叶斯统计中运用很多,MIT发布的EMCEE是实现的比较好的.介绍页面在下面.源代码中examples里的代码可以帮助理解各种功能,特别是line.py 列出了最小二乘法,最大似然法和M ...
- Codeforces--839A--Arya and Bran
题目 Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is goi ...
最新文章
- Spring boot访问静态资源
- 关于函数,对象以及闭包的一些理解
- mybatis实现动态sql语句
- 微信小程序 点击按钮 退出
- 浅说深度学习(1):核心概念
- VMware Sphere 虚拟磁盘创建选项
- 拓端tecdat|R语言参数检验 :需要多少样本?如何选择样本数量
- SCI论文降重技巧盘点 - 易智编译EaseEditing
- Jetson Xavier NX使用Yolov5+DeepStream+TensorRT实现CSI摄像头的目标识别及采坑记录
- Linux系统设置固定ip
- python中面向对象编程简称为_Python-面向对象编程
- mysql 多表中间表查询_mysql多表连接查询
- SSMS错误代码大全
- 设备树学习(二十三、番外篇-中断子系统之softirq)
- 使用的tk集成mybatis,报No MyBatis mapper was found in的警告解决方案
- 电信联通上海分别启用181与185号段
- Web3.0时代来临。企业该如何无痛接轨、加值商模?
- GBase 8a MPP Cluster SQL基础
- delphi 数字转字符串补全
- iOS上架及证书最新创建流程
热门文章
- 常见移动机器人运动学模型总结
- 云计算课程设计基于hadoop的词频统计设计
- vue 实现前端excel导出表格携带token的两种方法
- 第三十一课 ERC1410标准从分析到代码实现
- Linux文本三剑客--grep、sed、awk
- ansys workbench汉化教程_FC魔法阵咕噜咕噜汉化版下载-街机魔法阵咕噜咕噜完美汉化版下载...
- python pip怎么安装包_python怎么用pip安装包
- Mac下面visio的替代品Omnigraffle,很好用
- 学会以下几个软件你就会3D游戏模型了
- 研究报告 | 珠光宝气加持,谁能抓住“促消费”的东风?