Landscape Improved

Time limit1sMemory limit256 MB

Summary
Place up to n stones on a rocky skyline under pyramid support rules to push the highest peak as high as possible.
Level

Medium6 of 10

Topics
Binary search, Prefix sum
Solved
No attempts yet

Problem

King Louis L Le Roi-Univers has ordered his staff to improve the view from the royal palace. His Majesty wants to see a high mountain.

The Chief Landscape Manager is going to raise a mountain for the king. He draws the landscape as a flat picture on a grid of unit squares. Some squares are already filled with rock and the rest are empty. That simplifies the design a great deal. Unit squares are small enough that the landscape still looks smooth from the palace.

The Chief Landscape Manager has a plan of the landscape: the height of the rock in every column of the grid. He wants to put at most nn unit squares of stone on top of the existing landscape so that the peak is as high as possible. Piles of stone are unstable. A unit square of stone may be placed only directly on top of a square that is already filled with stone or rock, and the squares immediately to its bottom left and bottom right must be filled as well. No squares exist outside the given width, so those positions never count as filled. Rock that is already there is not affected by this condition and stays where it is.

Existing landscapeImproved landscape
Existing landscapeImproved landscape

Find the maximum height of the highest mountain the Chief Landscape Manager can build.

Input

The first line contains two integers ww, the width of the existing landscape, and nn, the maximum number of stone squares to add (1≤w≤1000001 \le w \le 100000, 0≤n≤10180 \le n \le 10^{18}).

Each of the next ww lines contains one integer hih_i, the height of one column of the existing landscape (1≤hi≤1091 \le h_i \le 10^9).

Output

Print one integer: the maximum landscape height after at most nn unit squares of stone have been added in a stable way.

Examples2

  1. Example 1

    Input
    8 4
    3
    4
    2
    1
    3
    3
    2
    4
    
    Expected output
    5
    
  2. Example 2

    Input
    3 100
    3
    3
    3
    
    Expected output
    4