CodeForces 363B Fence
Fence
This problem will be judged on CodeForces. Original ID: 363B
64-bit integer IO format: %I64d Java class name: (Any)
Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1]
Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.
Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic).
Input
The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence.
Output
Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them.
Sample Input
7 3
1 2 6 1 1 7 1
3
Hint
In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
Source
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
int n,k,sum[maxn];
int main(){
while(~scanf("%d %d",&n,&k)){
int theMin = INT_MAX,idx = -;
for(int i = ; i <= n; ++i){
scanf("%d",sum+i);
sum[i] += sum[i-];
if(i >= k && sum[i] - sum[i-k] < theMin){
theMin = sum[i] - sum[i-k];
idx = i - k + ;
}
}
printf("%d\n",idx);
}
return ;
}
CodeForces 363B Fence的更多相关文章
- codeforces 448CPainting Fence
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/y990041769/article/details/37935237 题目:codeforces 4 ...
- codeforces B.Fence 解题报告
题目链接:http://codeforces.com/problemset/problem/363/B 题目意思:给定整数n和k,需要从n个数中找出连续的k个数之和最小,输出这连续的k个数中的第一个数 ...
- codeforces 232D Fence
John Doe has a crooked fence, consisting of n rectangular planks, lined up from the left to the righ ...
- Codeforces 659G Fence Divercity dp
Fence Divercity 我们设a[ i ] 为第 i 个围栏被切的最靠下的位置, 我们发现a[ i ] 的最大取值有一下信息: 如果从i - 1过来并在 i 结束a[ i ] = min(h ...
- codeforces 363B
#include<stdio.h> #include<string.h> #define inf 999999999 #define N 151000 int a[N],c[N ...
- codeforces 349B Color the Fence 贪心,思维
1.codeforces 349B Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...
- Codeforces 484E Sign on Fence(是持久的段树+二分法)
题目链接:Codeforces 484E Sign on Fence 题目大意:给定给一个序列,每一个位置有一个值,表示高度,如今有若干查询,每次查询l,r,w,表示在区间l,r中, 连续最长长度大于 ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) E. Sign on Fence
http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护 ...
- Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题
A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...
随机推荐
- Calling convention-调用约定
In computer science, a calling convention is an implementation-level (low-level) scheme for how subr ...
- 优动漫PAINT-简单的树、叶教学
如题,简单.好用:其实说的还是一个观察的事.看你是否足够细心,对于树叶的生长.枝桠和树干的关系是否了解咯. 对于这样的树枝丫和叶子完全可以使用优动漫PAINT完成,简单又快捷,软件下载:www.don ...
- 关于注意力机制(《Attention is all you need》)
深度学习做NLP的方法,基本上都是先将句子分词,然后每个词转化为对应的词向量序列.(https://kexue.fm/archives/4765) 第一个思路是RNN层,递归进行,但是RNN无法很好地 ...
- canvas 连线曲线图封装
$.fn.hChart=function (opt) { var setting=$.extend({ className:'', data:[] },opt); var tbody=this; va ...
- 堆(Heap)-c实现
这个堆的实现采用数组存储的完全二叉树实现. 最近有点烦躁,先是跳槽到了一个外包公司,感觉2016有点坑,另外一件事就是老婆怀孕了,但是在家里没人照顾,很担心. 这个堆的实现就暂时不优化了,基本的插入, ...
- MySql5.7免安装版配置过程(ubuntu16.04)
MySql5.7免安装版配置过程(ubuntu16.04) 原创 2017年02月07日 16:58:24 标签: 1001 编辑 删除 一.安装环境: 操作系统:ubuntu16.04 数据库:my ...
- SCN 时间戳的相互转换
SQL> select * from v$version where rownum=1; BANNER --------------------------------------------- ...
- SolrCloud怎样创建跟新索引信息
发送leader,由leader定位地址.然后写到shard上,同一时候copy到replicaton . 如图
- mysql-安全管理
一.管理用户 用户账号和信息存放在数据库中 use mysql; select user form user; mysql数据库中包含一个user的表,它包含所有用户账号. user表中右移个名为us ...
- JS学习笔记-数据类型
最初的JS学习已经过去大半年的时间了,至此感觉对JS的使用与理解并非非常深入,因此在近期的工作之余也開始了新一轮的JS学习. 几天时间过去了,对于一些基础内容的学习还是非常有必要的,就从今天的又一次整 ...