Codeforces 839A Arya and Bran【暴力】
A. 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.
题目链接:http://codeforces.com/contest/839/problem/A
分析:题意大概是第n天结束之前需要给予Bran k糖果的最少天数,暴力即可,不过这题目题意确实有点迷就是了!
下面给出AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int ans=;
for(int i=;i<=n;i++)
{
int x;
cin>>x;
ans+=x;
m-=min(ans,);
ans-=min(ans,);
if(m<=)
return !printf("%d\n",i);
}
return !printf("-1\n");
}
Codeforces 839A Arya and Bran【暴力】的更多相关文章
- 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 ...
- 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 ...
- 839A Arya and Bran
A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #428 A. Arya and Bran【模拟】
A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- 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 #428 (Div. 2) A】Arya and Bran
[Link]: [Description] [Solution] 傻逼题 [NumberOf WA] [Reviw] [Code] #include <bits/stdc++.h> usi ...
- Codeforces Gym 100015H Hidden Code 暴力
Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...
- Codeforces gym 100685 A. Ariel 暴力
A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...
- Codeforces Gym 100637G G. #TheDress 暴力
G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...
随机推荐
- jQuery 最外面的那层皮
这次学习 jQuery 源码,基于当前最新的版本,3.2.1. IIFE (function() { 'use strict'; // })(); 定义一个匿名函数并立即执行,得益于 javascri ...
- 向map中追加元素
public class Demo01 { public static void main(String[] args) { String mapKey = "a"; Map< ...
- nova创建虚拟机源码系列分析之二 wsgi模型
openstack nova启动时首先通过命令行或者dashborad填写创建信息,然后通过restful api的方式调用openstack服务去创建虚拟机.数据信息从客户端到达openstack服 ...
- ES6 函数的扩展(1)
1. 函数参数的默认值 基本用法 在ES6之前,不能直接为函数的参数指定默认值,为了避免这个问题,通常需要先判断一下参数y是否被赋值,如果没有,再等于默认值. ES6允许为函数的参数设置默认值,即直接 ...
- 学习 Kubernetes 的 Why 和 How - 每天5分钟玩转 Docker 容器技术(114)
这是一个系统学习 Kubernetes 的教程,有下面两个特点: 系统讲解当前最流行的容器编排引擎 Kubernetes包括了安装部署.应用管理.网络.存储.监控.日志管理等多各个方面. 重实践并兼顾 ...
- Linux(CentOS6.5)下编译安装MySQL Community Server 5.7.12
组件 官方网站 直接下载地址 备注 mysql http://dev.mysql.com/downloads/mysql/ http://mirrors.sohu.com/mysql/MySQL- ...
- Android SDK Manager配置
Android SDK Manager就是一个Android软件开发工具包管理器,就像一个桥梁,连通本地和服务器,从服务器下载安卓开发所需工具到本地. 而AVD Manager是一个Android虚拟 ...
- Weblogic用户名密码获取
1.获取服务器上的Weblogic用户名.密码 工具:Xshell 第一步:连接至服务器上,新建目录: mkdir /scripts/DecryptionDemo 第二步:将Decrypt.java放 ...
- Python核心编程--浅拷贝与深拷贝
一.问题引出浅拷贝 首先看下面代码的执行情况: a = [1, 2, 3] print('a = %s' % a) # a = [1, 2, 3] b = a print('b = %s' % b) ...
- arm-linux-objdump反汇编使用指南
一. arm-linux-objdump常用来显示二进制文件信息,常用来查看反汇编代码 二. 常用选项: 1.-b bfdname 指定目标码格式 2.-disassemble或者-d 反汇编 ...