Fence

Time Limit: 1000ms
Memory Limit: 262144KB

This problem will be judged on CodeForces. Original ID: 363B
64-bit integer IO format: %I64d      Java class name: (Any)

There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights.

 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 jj + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them.

 

Sample Input

Input
7 3
1 2 6 1 1 7 1
Output
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的更多相关文章

  1. codeforces 448CPainting Fence

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/y990041769/article/details/37935237 题目:codeforces 4 ...

  2. codeforces B.Fence 解题报告

    题目链接:http://codeforces.com/problemset/problem/363/B 题目意思:给定整数n和k,需要从n个数中找出连续的k个数之和最小,输出这连续的k个数中的第一个数 ...

  3. codeforces 232D Fence

    John Doe has a crooked fence, consisting of n rectangular planks, lined up from the left to the righ ...

  4. Codeforces 659G Fence Divercity dp

    Fence Divercity 我们设a[ i ] 为第 i 个围栏被切的最靠下的位置, 我们发现a[ i ] 的最大取值有一下信息: 如果从i - 1过来并在 i  结束a[ i ] = min(h ...

  5. codeforces 363B

    #include<stdio.h> #include<string.h> #define inf 999999999 #define N 151000 int a[N],c[N ...

  6. codeforces 349B Color the Fence 贪心,思维

    1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...

  7. Codeforces 484E Sign on Fence(是持久的段树+二分法)

    题目链接:Codeforces 484E Sign on Fence 题目大意:给定给一个序列,每一个位置有一个值,表示高度,如今有若干查询,每次查询l,r,w,表示在区间l,r中, 连续最长长度大于 ...

  8. 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的数 维护 ...

  9. 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 ...

随机推荐

  1. 【转载】Reactor模式和NIO

    当前分布式计算 Web Services盛行天下,这些网络服务的底层都离不开对socket的操作.他们都有一个共同的结构:1. Read request2. Decode request3. Proc ...

  2. STM8S103汇编文档和注意

    1.官方文档<STM8 CPU programming manual>介绍了指令和寻址方式 2.辅助类文档,boot loader文档<STM8 bootloader> 3.关 ...

  3. Python数据分析前提-----pandas

    1.read_csv(url):读取数据 2.help(read_csv):打印函数相关用法 3.数据名.dtypes:读取数据的类型(int.float……) 4.type(数据名):读取所有数据的 ...

  4. [LOJ2422]【NOIP2015】斗地主

    大名鼎鼎的NOIP2015D1T3 题意: 由于一些众所周知的原因,没有完整题面…… 给你一副斗地主的手牌(牌数<=23),问最少要几次能出完: 包含双王,没有癞子,连对要三连对以上,可以直接出 ...

  5. BZOJ 1085 / LOJ 2151 [SCOI2005]骑士精神 (剪枝/A*迭代搜索)

    题目大意:略 直接爆搜会T,我们优化一下,统计出当前棋盘和目标棋盘不同的位置的数量k,那么当前棋盘变成目标棋盘最少的移动次数是k-1 每次选择一个最大深度ma,那么如果当前走了dep步,显然必须保证d ...

  6. sql 技巧

    1.想把一张表的 某个字段或多个字段 的 所有数据 复制到另外一张表里  insert into 表名(字段) select (字段) from 表名 2.from Users u , IN(u.ro ...

  7. python购物车系统

    购物车系统模拟:product_list = [ ('java',100), ('python',200), ('键盘',500), ('电脑',4000), ('mac Book',7000),]S ...

  8. C#打开或者创建一个文件,然后向其末尾写入数据的方法

    原文:C#打开或者创建一个文件,然后向其末尾写入数据的方法             FileStream fs = new FileStream(@"d:\timetick.txt" ...

  9. 11g Oracle Rac安装(基于linux6)可能出现的问题

    11g Oracle Rac安装(基于linux6)可能出现的问题汇总: 7)使用"yum"命令执行节点的自动配置失败. 修改一下 /etc/resolv.conf,添加: nam ...

  10. FS,FT,DFT,DFS和DTFT的关系

    对于初学数字信号(Digital Signal Processing,DSP)的人来说,这几种变换是最为头疼的,它们是数字信号处理的理论基础,贯穿整个信号的处理. FS:时域上任意连续的周期信号可以分 ...