#P796. Fence ( 圍欄 )

    ID: 796 Type: Default 400ms 64MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>1100BASICn行t行Codeforces Round #211

Fence ( 圍欄 )

題目描述

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.

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

Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1]

波利卡普斯的家門前有一道柵欄。 柵欄由n塊相同寬度的木板組成,從左到右依次排列。 第 i 個木板的高度是 hi 米,不同的木板可以有不同的高度。

Polycarpus 買了一架豪華鋼琴,正在考慮如何把它裝進屋裡。 為了執行他的計劃,他需要從柵欄上連續取 k 塊木板。 更高的木板更難從柵欄上撕下來,所以 Polycarpus 想要找到這樣的 k 個連續木板,它們的高度之和是最小的。

編寫程序,找出總高度最小的 k 個連續木板的索引。 注意,圍欄不是在波利卡普斯的家周圍,而是在家裡的前面(換句話說,圍欄不是循環的)。

輸入格式

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.

輸入的第一行包含整數 n 和 k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — 柵欄上的木板數量和鋼琴孔的寬度。 第二行包含整數序列 h1, h2, ..., hn (1 ≤ hi ≤ 100),其中 hi 是圍欄的第 i 個木板的高度。

輸出格式

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.

打印這樣的整數 j,使得木板 j、j + 1、...、j + k - 1 的高度之和是可能的最小值。 如果有多個這樣的 j,打印其中任何一個。

Samples

7 3
1 2 6 1 1 7 1
3

提示

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.

在示例中,您的任務是找到三個具有最小高度總和的連續木板。 在給定的情況下,索引為 3、4 和 5 的三塊木板具有所需的屬性,它們的總高度為 8。

原始資料

  • Zero1 題號:a796
  • Hydro 題號:Z0796
  • Locale:zh_TW
  • Display:open