Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/qidiruv-daraxt-kesish

Cutting trees

Hard 1000 ms 128 MB 67%
Share

A woodcutter needs $m$ metres of wood. $n$ trees grow in a row, the height of the $i$-th one is $a_{i}$. He sets the saw at an integer height $H \ge 0$: every tree taller than $H$ loses its part above $H$ ($a_{i} - H$ metres), the other trees are not touched. Find the largest value of $H$ at which at least $m$ metres of wood are obtained.

Tree columns, a horizontal line at the saw height and the highlighted parts above it that are cut off

Input

The first line contains two positive integers: $n$ and $m$. The second line contains $n$ positive integers $a_{i}$ separated by spaces.

Output

One integer — the largest value of $H$.

Note

$1 \le n \le 10^{5}$
$1 \le a_{i} \le 10^{9}$
$1 \le m \le a_{1} + a_{2} + \dots + a_{n} \le 10^{14}$

Examples

Input #1
4 7
20 15 10 17
Output #1
15
Input #2
3 6
5 5 5
Output #2
3

Sign in to submit a solution

Signing up is free and takes a minute.