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 ;
}
最新文章
- .NET跨平台之旅:数据库连接字符串写法引发的问题
- go程序注册为windows服务
- Javascript - Arraylike的7种实现
- mysql数据库优化小结
- C# 点绕某点旋转某角度
- iOS 可延展视图(点击前显示部分文字,点击后显示全部)
- Ogre分层渲染 (转)
- Linux怪哉ntfs
- Delphi 缩放图像代码 - 支持PNG透明通道(利用了Windows的windowscodecs.dll)
- Tomcat学习笔记 - 错误日志 - NetBeans配置tomcat出错情况总结 -- 部署错误: 启动 Tomcat 失败。-- &#39;127.0.0.1&#39; 不是内部或外部命令,也不是可运行的程序
- 04-UIKit(UINavigationController、NSAttributeString、UIImageView)
- ThreadLocal 遇上线程池的问题及解决办法
- 深入理解android6.0 RunTime Permisstion
- Web前端新手想提升自身岗位竞争力,需做好这3件事!
- Redis笔记(四):Redis事务支持
- 如何使用C#程序给PDF文件添加编辑域
- bzoj5123 [Lydsy12月赛]线段树的匹配
- python学习笔记(十三)之lambda表达式
- 关于/proc/进程idpid/fd ,根据fd来查找连接
- 什么是“QQ登录OAuth2.0”