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 ...
随机推荐
- 5月17 AJAX返回类型-------JSON和XML
ajax返回类型有TEXT,JSON,XML 一.TEXT 查看之前的练习 二.JSON var js = { aa:{code:"p001",name:"张三" ...
- vue element upload图片 回显问题
beforeUpload (file) { var _this = this; var reader = new FileReader(); reader.readAsDataURL(file); ...
- VMware(虚拟机) 12版安装深度linux系统
需要的工具: 1.VM ware workstation12虚拟机(可自行百度下载) 参考:VMware Workstation 12.5.5 官方中文正式版,下载地址:http://www.epi ...
- HDU-6395-矩阵快速幂
Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- Python面向对象之继承
前言: 继承是面向对象的3大特性之一,对于继承一点要注意一下4点. 一.基本查找 如果子类继承了父类,子类的实例化对象,没有的方法和属性会去父类找 class Parent(object): #父类 ...
- id: cannot find name for user ID xxx处理办法
一.现像 root用户登录显示正常但以普通用户登录时报类似如下错误: id: cannot find name for user ID 500id: cannot find name for grou ...
- QPainter绘制渐进色文本
参考资料:https://blog.csdn.net/what951006/article/details/52876513 效果图: 代码: void WgtText::paintEvent(QPa ...
- 字符串和数组----string
一.初始化string对象的方式 #include <iostream> #include <string> using std::cout; using std::endl; ...
- python-time,datetime
1.time模块:time.time() # 返回当前时间的时间戳(1970纪元后经过的浮点秒数)time.localtime([ sec ]) # 接收时间戳(默认为当前时间),返回struct_t ...
- MySQL(一) 初识MySQL
数据库基础 数据库是由一批数据构成的有序的集合,这些数据被存放在结构化的数据表里.数据表之间相互联系,反映了客观事物间的本质联系.数据库系统提供对数据的安全控制和完整性控制. 什么是数据库 数据库的发 ...