CF363B.Fence

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

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

Polycarpus 家门前有一道栅栏。该栅栏由 nn 块宽度相同的木板组成,从左到右依次排列。第 ii 块木板的高度为 hih_i 米,不同木板的高度可以不同。

n=7n = 7 且 h=[1, 2, 6, 1, 1, 7, 1]h = [1,\ 2,\ 6,\ 1,\ 1,\ 7,\ 1] 时的栅栏示意图

Polycarpus 购买了一架高档钢琴,正在思考如何将它搬进家中。为实现这一计划,他需要恰好从栅栏上拆下 kk 块连续的木板。木板越高,拆卸难度越大,因此 Polycarpus 希望找到这样一段长度为 kk 的连续木板,使其总高度尽可能小。

请编写一个程序,找出总高度最小的 kk 块连续木板的起始与结束下标(即索引)。注意:该栅栏并非环绕 Polycarpus 家屋(即不是环形结构),而是位于房屋正前方(线性结构)。

输入格式

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.

输入的第一行包含两个整数 nn 和 kk(1 ≤ n ≤ 1.5⋅1051 ≤ n ≤ 1.5·10^5,1 ≤ k ≤ n1 ≤ k ≤ n)—— 分别表示围栏中木板的数量以及钢琴所需空洞的宽度。
第二行包含一个整数序列 h1, h2, ..., hnh_1, h_2, ..., h_n(1 ≤ hi ≤ 1001 ≤ h_i ≤ 100),其中 hih_i 表示围栏中第 ii 块木板的高度。

输出格式

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.

输出满足条件的整数 jj,使得木板 jj、j+1j+1、…、j+k−1j+k-1 的高度之和最小。若存在多个满足条件的 jj,输出其中任意一个即可。

输入输出样例

  • 输入#1

    7 3
    1 2 6 1 1 7 1

    输出#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。

输入解题思路,AI测评打分。不知道怎么写?

首页