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

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

Problem Description

Lumberjack Mirko needs to chop down MM metres of wood. It is an easy job for him since he has a nifty new woodcutting machine that can take down forests like wildfire. However, Mirko is only allowed to cut a single row of trees.

Mirko's machine works as follows: Mirko sets a height parameter HH (in metres), and the machine raises a giant sawblade to that height and cuts off all tree parts higher than HH (of course, trees not higher than HH meters remain intact). Mirko then takes the parts that were cut off. For example, if the tree row contains trees with heights of 2020, 1515, 1010, and 1717 metres, and Mirko raises his sawblade to 1515 metres, the remaining tree heights after cutting will be 1515, 1515, 1010, and 1515 metres, respectively, while Mirko will take 55 metres off the first tree and 22 metres off the fourth tree (77 metres of wood in total).

Mirko is ecologically minded, so he doesn't want to cut off more wood than necessary. That's why he wants to set his sawblade as high as possible. Help Mirko find the maximum integer height of the sawblade that still allows him to cut off at least MM metres of wood.

Input Format

The first line of input contains two space-separated positive integers, NN (the number of trees, 1N1061 ≤ N ≤ 10^6) and MM (Mirko‟s required wood amount, 1M2×1091 ≤ M ≤ 2\times10^9).

The second line of input contains NN space-separated positive integers less than 10910^9, the heights of each tree (in metres). The sum of all heights will exceed MM, thus Mirko will always be able to obtain the required amount of wood.

Output Format

The first and only line of output must contain the required height setting.

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