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 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<iostream>
#include<cstring>
#include<cstdio>
using namespace std; int main()
{
int n,k;
scanf("%d%d",&n,&k);
int a[],tmpk=,i;
bool flag=false;
for(i=;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=;i<n;i++)
{
if(a[i]>=)
{
tmpk+=;
a[i]-=;
a[i+]+=a[i];
}
else
{
tmpk+=a[i];
}
if(tmpk>=k)
{
flag=true;
break;
}
}
if(flag)
printf("%d\n",i+);
else
printf("-1\n");
return ;
}
codeforce 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 ...
- 839A Arya and Bran
A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- codeforce A. 2Char(水题,暴力)
今晚发了个蛇精病,然后CF了,第一题这好难啊,然而水题一个,暴力飘过. 链接http://codeforces.com/contest/593/problem/A: 题意比较难懂吗?傻逼百度都翻译不对 ...
- 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 #360 (Div. 2) A. Opponents 水题
A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...
- codeforces 688A A. Opponents(水题)
题目链接: A. Opponents time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- ACM :漫漫上学路 -DP -水题
CSU 1772 漫漫上学路 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
随机推荐
- 配置ssh免密登录
安装ssh sudo apt-get install ssh 产生密钥:ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa (rsa为ssh的加密方式 ...
- HBase之六:HBase的RowKey设计
数据模型 我们可以将一个表想象成一个大的映射关系,通过行健.行健+时间戳或行键+列(列族:列修饰符),就可以定位特定数据,Hbase是稀疏存储数据的,因此某些列可以是空白的, Row Key Time ...
- python-django缓存
三 Django的缓存机制 1.1 缓存介绍 1.缓存的简介 在动态网站中,用户所有的请求,服务器都会去数据库中进行相应的增,删,查,改,渲染模板,执行业务逻辑,最后生成用户看到的页面. 当一个网站的 ...
- python-day91--同源策略与Jsonp
一.同源策略 同源策略(Same origin policy)是一种约定,它是浏览器最核心也最基本的安全功能,如果缺少了同源策略,则浏览器的正常功能可能都会受到影响.可以说Web是构建在同源策略基础之 ...
- BIT-区间修改单点查询
正好刷题时碰到了这个之前遇到过的问题,类似的还有区间修改区间查询,以后学了会补上. 我们知道BIT只支持单点修改区间查询,如果现在问题变成每次让一个区间的数同时变化,然后询问的是某一个点得值的时候该怎 ...
- 大数据分析引擎Apache Flink
Apache Flink是一个高效.分布式.基于Java实现的通用大数据分析引擎,它具有分布式 MapReduce一类平台的高效性.灵活性和扩展性以及并行数据库查询优化方案,它支持批量和基于流的数据分 ...
- 解决nginx重启“var/run/nginx/nginx.pid" no such file or directory问题
重启虚拟机后,再次重启nginx会报错“/var/run/nginx/nginx.pid” no such file or directory. 方法一(已试过可行): 到/var/run下看没有ng ...
- maven聚合工程使用如何debug
maven聚合工程在正常情况下,使用debug时会出错,因为没有源码,就不会显示代码和断点行数条. 进行如下操作: 默认情况下source下只有默认的default文件夹,点击remove进行删除(这 ...
- FastDFS安装教程
1.下载 FastDFS下载:https://codeload.github.com/happyfish100/fastdfs/zip/master 库文件下载:https://codeload.gi ...
- latex 公式距离
\setlength{\abovedisplayshortskip}{0cm} 公式和文本之间的间距 \setlength{\belowdisplayshortskip}{0cm} \setlengt ...