Minas Gerais’ walls

시간 제한0.5초메모리 제한2048 MB

요약
한 구간을 골라 K, K-1, ..., 1개의 블록을 왼쪽으로 계단식으로 쌓은 뒤 얻을 수 있는 최소 높이의 최댓값을 구한다.
난이도

보통10점 중 6점

유형
이분 탐색, 누적 합, 그리디
정답자
아직 제출이 없습니다

문제

Due to their privileged location and favorable terrain, only frontal walls were usually necessary to protect medieval cities in Minas Gerais. Even today, it is possible to find traces of these constructions when admiring the beautiful horizon of the region.

Each of these walls was composed of a number of consecutive segments, each with an initial height measured in units, corresponding to the number of blocks used to build it.

From time to time, the builders reinforced the walls by choosing a segment and stacking extra blocks in a staircase pattern: the chosen segment received KK additional blocks, the previous one K−1K − 1, and so on until only 11 block was added or there were no more segments to the left.

The defense was considered as strong as its lowest segment.

Given the initial description of a wall, your objective is to determine the largest possible minimum height after applying a single reinforcement.

입력

The first line contains two integers NN (1≤N≤1051 ≤ N ≤ 10^5), the number of wall segments, and KK (1≤K≤N1 ≤ K ≤ N), the number of blocks added to the chosen segment.

The second line contains NN integers x_1,x_2,…,x_Nx\_1, x\_2, \dots , x\_N (1≤x_i≤1091 ≤ x\_i ≤ 10^9), representing the initial heights of the segments.

출력

Your program should print a single line, containing a single integer: the largest possible minimum height of the wall after a single reinforcement.

예제3

  1. 예제 1

    입력
    5 5
    5 4 3 2 1
    
    예상 출력
    6
    
  2. 예제 2

    입력
    6 1
    3 3 1 3 3 3
    
    예상 출력
    2
    
  3. 예제 3

    입력
    5 5
    3 4 7 8 7
    
    예상 출력
    7