Under construction

Still being built. Things may change

Balloon Factory

Interview

Time limit1sMemory limit256 MB

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

Medium5 of 10

Topics
Binary search, Greedy, Math, Array
Solved
No attempts yet

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 (1≤N,M≤1 000 0001 \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 (1≤Ai≤1 000 0001 \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.

Examples2

  1. Example 1

    Input
    3 8
    5 7 3
    
    Expected output
    14
    
  2. Example 2

    Input
    1 5
    7
    
    Expected output
    35