cswork / OAOpen practice workspace

AmazonOA #25

Find Minimum Maximum

Estimated MediumJudge-ready

Topics (AI-labelled)Binary SearchBits & Math

Existing parcels cannot be moved; distribute exactly extra new parcels among n couriers in any way. Parcels cannot be split. Find the minimum possible maximum load after distribution.

Input

The first line contains n extra (1≤n≤100000, 1≤extra≤10¹⁵); the second line contains n initial loads (1..10⁹).

Output

Output a single integer, the answer required by the problem.

Example 1

Input:

5 25
7 5 1 9 1

Output:

10

Example 2

Input:

2 1
9 1

Output:

9

Example 3

Input:

1 1
1

Output:

2

Example notes

Example 1: the original total is 23, and adding 25 makes 48, so the maximum load among the five couriers is at least ⌈48/5⌉=10; the loads can be 10, 10, 10, 9, 9, so the answer is 10. Example 2: give the 1 new parcel to the courier with load 1, making 9 and 2; the maximum is still 9. Example 3: the only courier's load goes from 1 to 2.

Editorial

Loading solution…