Balloon Factory

Find the minimum time for N workers, each producing one balloon every A_i minutes, to finish M balloons in parallel.

Medium5Binary searchGreedyMathArrayInterviewNo attempts yetTime limit1sMemory limit256 MB

Problem

There are NN staff members who share the work of making MM balloons. Staff member ii takes AiA_i minutes to make one balloon and can start the next balloon immediately after finishing one. All staff members start working together at minute 00. Find the minimum number of minutes needed until all MM balloons are finished. Balloon designs do not matter.

For example, a staff member who takes 55 minutes per balloon and starts at minute 00 finishes the first balloon at minute 55 and the second balloon at minute 1010.

Input

The first line contains the number of staff members NN and the number of balloons MM (1N,M10000001 \le N, M \le 1\,000\,000).

The second line contains NN integers, the time AiA_i in minutes each staff member takes to make one balloon (1Ai10000001 \le A_i \le 1\,000\,000).

Output

Print a single integer, the minimum number of minutes needed to finish all MM balloons.

Hint

Whether a candidate time of TT minutes is enough can be counted directly. Staff member ii finishes T/Ai\lfloor T / A_i \rfloor balloons within TT minutes, so MM balloons can be finished within TT minutes when the total over all staff members is at least MM. Binary-searching the range of possible times with this check gives the minimum time.