All problems

Problem 886

Maximum Running Time of N Computers

Hard · 30 pts · Array, Binary Search, Greedy

Problem

You want to run N computers at the same time. Battery i can power a computer for BATTERIES[i] minutes, and you may move batteries between computers at any moment, instantly, but each battery can power only one computer at a time. Find the maximum number of minutes all N computers can run together. They can run for T minutes exactly when the batteries, each counted as at most T minutes, provide at least N × T minutes in total, so binary search on T.

Input

The first line contains N and M. The second line contains the M battery capacities.

Output

Print the maximum running time.

Constraints

1 <= N <= M <= 100000; 1 <= BATTERIES[i] <= 10^9

Example input

2 3
3 3 3

Example output

4

Explanation

With 2 computers and batteries 3 3 3, run 4 minutes: two batteries power the computers for 3 minutes, then the third battery is split between them for one more minute each. The answer is 4.

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

Previous: Minimum Time to Repair Cars Next: Heaters