CF-839A
A. Arya and Brantime limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
InputThe 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).
OutputIf 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.
Examplesinput2 3
1 2output2input3 17
10 10 10output3input1 9
10output-1NoteIn 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.
题意:
每天一个数字,数可累积,每天最多减8,求最少需要多少天减值达到k。
AC代码:
#include<bits/stdc++.h>
using namespace std; int a[]; int main(){
ios::sync_with_stdio(false);
int n,k;
cin>>n>>k;
int ans=,flag=;
for(int i=;i<n;i++){
cin>>a[i];
ans+=a[i];
k-=min(ans,);
ans-=min(ans,);
if(k<=){
cout<<i+<<endl;
flag=;
break;
}
}
if(flag)
cout<<-<<endl;
return ;
}
CF-839A的更多相关文章
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- CF memsql Start[c]UP 2.0 A
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...
- CF memsql Start[c]UP 2.0 B
CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
- CF #375 (Div. 2) D. bfs
1.CF #375 (Div. 2) D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...
- CF #374 (Div. 2) D. 贪心,优先队列或set
1.CF #374 (Div. 2) D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...
随机推荐
- python 基础 3.2 文件 for 练习
#/usr/bin/python #coding=utf-8 #@Time :2017/11/1 22:19 #@Auther :liuzhenchuan #@File :1030-1031练 ...
- 【BZOJ4569】[Scoi2016]萌萌哒 倍增+并查集
[BZOJ4569][Scoi2016]萌萌哒 Description 一个长度为n的大数,用S1S2S3...Sn表示,其中Si表示数的第i位,S1是数的最高位,告诉你一些限制条件,每个条件表示为四 ...
- iOS 设置字体样式
1.iOS设置字体样式 label.font = [UIFont fontWithName:@"Arial-BoldItalicMT" size:24]; 字体名如下: F ...
- process_thread_action
import psycopg2 import threading conn_fmac = psycopg2.connect(database='filter_useless_mac', user='u ...
- 我的Android进阶之旅------>解决Your project contains error(s),please fix them
在使用eclipse写好Android的代码,代码没有报错.然后想在AVD中运行测试时,弹出错误框,提示信息为: "Your project contains error(s),pleas ...
- 用php動態產生各種尺寸的圖片
我的做法是用php動態產生各種尺寸的圖片,例如<img src="img.php?src=a.jpg&width=100&height=200"...< ...
- 【python】使用python写windows服务
背景 运维windows服务器的同学都知道,windows服务器进行批量管理的时候非常麻烦,没有比较顺手的工具,虽然saltstack和ansible都能够支持windows操作,但是使用起来总感觉不 ...
- 【总结】性能调优:JVM内存调优相关文章
[总结]性能调优:JVM内存诊断工具 [总结]性能调优:CPU消耗分析 [总结]性能调优:消耗分析 JVM性能调优
- PopupWindow 实现 查看所有手机应用弹出框
public class MainActivity extends Activity implements OnItemLongClickListener, OnClickListener { pri ...
- 【Leetcode-easy】Longest Common Prefix
思路:每次从字符数组中读取两个字符串比较.需要注意输入字符串为空,等细节. public String longestCommonPrefix(String[] strs) { if(strs==nu ...