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 ;
}

最新文章

  1. 牛逼的css3:动态过渡与图形变换
  2. jstl中格式化时间戳
  3. 【RabbitMQ】RabbitMQ的一些基础概念
  4. mysql grant ,User,revoke
  5. SSIS -&gt;&gt; 生成时间格式
  6. 通过AopTestUtils对切面对象进行mock
  7. 安装TDM-GCC
  8. Jsp连接Mysql数据库取数方法
  9. 职责链(Chain of Responsibility)模式
  10. HDU 1681 Frobenius(完全背包+标记装满)
  11. 浅谈一个网页打开的全过程(涉及DNS、CDN、Nginx负载均衡等)
  12. YII2 models非常好用的控制输出数据【重写Fields】
  13. Core Animation 文档翻译 (第五篇)
  14. [CentOS] rsync同步目录进行备份文件
  15. 获取多个checkbox的选中值
  16. 移动电源、3G路由拆机
  17. [译]CQRS介绍
  18. Python2.7-hashlib
  19. jQuery页面滚动图片等元素动态加载实现
  20. PAT 乙级 1037 在霍格沃茨找零钱(20)C++版

热门文章

  1. 阿里巴巴和印度最大移动支付和商务平台Paytm
  2. 如何在SQLServer中处理每天四亿三千万记录的
  3. PostgreSQL 索引膨胀
  4. POJ 2481 Cows【树状数组】
  5. HDU 1505 City Game【DP】
  6. SAI 绘画一个卡通动漫人物详解
  7. 在学校机房联想硬盘保护下安装Linux,并配置锐捷客户端
  8. java实现websocket 终极指南
  9. puppet介绍与安装
  10. HDFS架构与原理