All problems

Problem 885

Minimum Time to Repair Cars

Medium · 20 pts · Array, Binary Search

Problem

Each mechanic has a rank R; a mechanic of rank R needs R × n² minutes to repair n cars. All mechanics work at the same time. Find the minimum number of minutes needed to repair CARS cars in total. In T minutes a mechanic of rank R can repair floor(√(T / R)) cars, so binary search on T and check whether the mechanics together can repair at least CARS cars. Answers reach about 10^14, so use 64-bit integers.

Input

The first line contains N and CARS. The second line contains the N ranks.

Output

Print the minimum time.

Constraints

1 <= N <= 100000; 1 <= rank <= 100; 1 <= CARS <= 10^6

Example input

4 10
4 2 3 1

Example output

16

Explanation

With ranks 4 2 3 1 and 10 cars, in 16 minutes the mechanics can repair 2, 2, 2 and 4 cars (for example rank 1 repairs 4 cars in 16 minutes). Ten cars do not fit in 15 minutes, so the answer is 16.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Search in a Mountain Array Next: Maximum Running Time of N Computers