363B.md (1964B)
1 Source: https://codeforces.com/problemset/problem/363/B 2 3 B. Fence 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 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 have distinct heights. 22 23  Fence for *n* = 7 and *h* = [1, 2, 6, 1, 1, 7, 1] 24 25 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. 26 27 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). 28 29 Input 30 31 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 *h*1, *h*2, ..., *h**n* (1 ≤ *h**i* ≤ 100), where *h**i* is the height of the *i*-th plank of the fence. 32 33 Output 34 35 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. 36 37 Examples 38 39 Input 40 41 ``` 42 7 3 43 1 2 6 1 1 7 1 44 ``` 45 46 Output 47 48 ``` 49 3 50 ``` 51 52 Note 53 54 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.