#P1873. [COCI 2011/2012 #5] EKO / 砍树

[COCI 2011/2012 #5] EKO / 砍树

Description

Lumberjack Mirko needs to cut MM meters of wood. This is easy for Mirko because he has a shiny new woodcutting machine that can cut through a forest like wildfire. However, Mirko is allowed to cut only one row of trees.

The machine works as follows: Mirko sets a height parameter HH (in meters), the machine raises a huge saw blade to height HH, and it cuts off the part of every tree that is higher than HH (of course, trees not higher than HH remain unchanged). Mirko then collects the cut-off parts. For example, if a row of trees has heights 20,15,1020, 15, 10 and 1717, and Mirko raises the blade to 1515 meters, after cutting the remaining heights will be 15,15,1015, 15, 10 and 1515, and Mirko will get 55 meters from the 11st tree and 22 meters from the 44th tree, 77 meters in total.

Mirko cares about the environment, so he will not cut more wood than necessary. This is why he sets the saw blade as high as possible. Help Mirko find the maximum integer height HH such that the amount of wood he obtains is at least MM meters. In other words, if he raised it by 11 meter more, he would not obtain MM meters of wood.

Input Format

The first line contains two integers NN and MM, where NN is the number of trees and MM is the required total length of wood.

The second line contains NN integers, the heights of the trees.

Output Format

Output a single integer, the highest possible blade height.

4 7
20 15 10 17
15
5 20
4 42 40 26 46
36

Hint

For 100%100\% of the testdata, 1N1061 \le N \le 10^6, 1M2×1091 \le M \le 2 \times 10^9, tree height 4×105\le 4 \times 10^5, and the sum of all tree heights >M> M.

Translated by ChatGPT 5