B. Fence
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

Examples
input
7 3
1 2 6 1 1 7 1
output
3
Note

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.

求连续的k个数和的最小值,要求输出下标

前缀和瞎搞  O(n)

/* ***********************************************
Author :guanjun
Created Time :2016/10/7 16:24:54
File Name :cf211b.cpp
************************************************ */
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
int dp[];
int a[];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int n,k,ans;
while(cin>>n>>k){
for(int i=;i<=n;i++)cin>>a[i];
dp[]=;
ans=;
for(int i=;i<=k;i++)dp[i]=dp[i-]+a[i]; int Min=dp[k];
for(int i=+k;i<=n;i++){
dp[i]=dp[i-]+a[i];
int tmp=dp[i]-dp[i-k];
if(tmp<Min){
Min=tmp;
ans=i-k+;
}
}
cout<<ans<<endl;
}
return ;
}

Codeforces Round #211 (Div. 2)B. Fence的更多相关文章

  1. Codeforces Round #211 (Div. 2)

    难得一次比赛能够自己成功A掉四个题: A题:水题,模拟一下就行: #include <iostream> #include <cstdio> using namespace s ...

  2. Codeforces Round #346 (Div. 2) G. Fence Divercity dp

    G. Fence Divercity 题目连接: http://www.codeforces.com/contest/659/problem/G Description Long ago, Vasil ...

  3. Codeforces Round #211 (Div. 2) D题(二分,贪心)解题报告

    ---恢复内容开始--- 题目地址 简要题意: n个小伙子一起去买自行车,他们有每个人都带了一些钱,并且有公有的一笔梦想启动资金,可以分配给任何小伙子任何数值,当然分配权在我们的手中.现在给出m辆自行 ...

  4. Codeforces Round #211 (Div. 2)-D. Renting Bikes,二分!感谢队友出思路!

    D. Renting Bikes 读懂题后一开始和队友都以为是贪心.可是贪心又怎么贪呢..我们无法确定到底能买多少车但肯定是最便宜的前x辆.除了公共预算每个人的钱只能自己用,也无法确定每个人买哪一辆车 ...

  5. Codeforces Round #117 (Div. 2)

    Codeforces Round #117 (Div. 2) 代码 Codeforces Round #117 (Div. 2) A. Battlefield any trench in meters ...

  6. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. SpringBoot项目的mybatis逆向工程

    <dependencies> <!--mybatis--> <dependency> <groupId>org.mybatis.spring.boot& ...

  2. Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean

    WebsocketSourceConfiguration { @Bean ServletWebServerFactory servletWebServerFactory(){ return new T ...

  3. 输入一个链表,按链表值从尾到头的顺序返回一个ArrayList

    package algorithms; import java.util.ArrayList; import java.util.Stack; /** * public class ListNode ...

  4. Python爬虫:抓取手机APP的数据

    摘要 大多数APP里面返回的是json格式数据,或者一堆加密过的数据 .这里以超级课程表APP为例,抓取超级课程表里用户发的话题. 1.抓取APP数据包 表单: 表单中包括了用户名和密码,当然都是加密 ...

  5. js数组的处理

    //重写Array中的indexOf方法,获取数组中指定值的元素的索引 Array.prototype.indexOf = function (val) { for (var i = 0; i < ...

  6. Linux常用命令——压缩与解压缩命令

    常用压缩格式:  .zip   .gz   .bz2   .tar.gz   .tar.bz2 1..zip格式压缩 zip 压缩文件名 源文件 压缩文件 zip -r 压缩文件名 源目录 压缩目录 ...

  7. 19异常和file部分笔记

    19异常和file部分笔记-2018/09/041.异常  1.1 throwable()几个常见方法 * getMessage()获取异常信息,返回字符串 * toString()获取异常类名和异常 ...

  8. CentOS7安装Nginx及其相关

    一.安装所需环境 gcc 安装 安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装. yum install gcc-c++ PCRE pcr ...

  9. centos7安装:license information(license not accepted)

    安装centos7的时候明明已经选择了默认的许可证信息,不知道哪里出错了,安装到最后,就会显示license information(license not accepted)的信息.解决方法如下: ...

  10. 高德地图将字符串地址转为经纬度的一个demo

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta http ...