Fencetime limit:1000msmemory limit:262144kbthis problem'll be judged onCodeforces. 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
h
i meters, distinct planks can has distinct HEI Ghts.
Fence for
n = 7 and
h = [1, 2, 6, 1, 1, 7, 1]
Polycarpus has bought a posh piano and was 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 is harder to tear off the fence, so Polycarpus wants to find such K consecutive planks that th e Sum of their heights is minimal possible.
Write The program This finds the indexes of K consecutive planks with minimal total height. Pay attention, the fence are not around Polycarpus's home, it's 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, ..., h N (1≤ hi ≤100), where hi is the height of the i-th plank of the fence.
Output
Print such integer j that sum of the heights of planks J, J + 1, ..., J + k -1 is the minimum possible. If There is multiple such J' s, print any of them.
Sample InputInput
7 3
1 2 6 1 1 7 1
Output
3
Hint
In the sample, your task was to find three consecutive planks with the minimum sum of heights. The given case three planks with indexes 3, 4 and 5 has the required attribute, their total height is 8.
SourceCodeforces Round #211 (Div. 2) Problem solving: screwing around
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN =200010;4 intN,K,SUM[MAXN];5 intMain () {6 while(~SCANF ("%d%d",&n,&k)) {7 intThemin = Int_max,idx =-1;8 for(inti =1; I <= N; ++i) {9scanf"%d", sum+i);TenSum[i] + = sum[i-1]; One if(i >= k && sum[i]-sum[i-k] <themin) { AThemin = sum[i]-sum[i-K]; -IDX = I-k +1; - } the } -printf"%d\n", idx); - } - return 0; +}
View Code
Codeforces 363B Fence