cswork / OA打开练习工作台

AmazonOA #25

Find Minimum Maximum

估计中等可在线判题

考点(AI 标注)二分查找位运算

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.

输入格式

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

输出格式

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

样例 1

输入:

5 25
7 5 1 9 1

输出:

10

样例 2

输入:

2 1
9 1

输出:

9

样例 3

输入:

1 1
1

输出:

2

样例说明

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.