Problem 873
Minimized Maximum of Products Distributed to Any Store
Medium · 20 pts · Array, Binary Search
Problem
There are N stores and M product types; QUANTITIES[i] items of type i must all be given out. A store can receive items of at most one type, any amount of it, and some stores may get nothing. Minimise the largest number of items any store receives. If no store may get more than X items, type i needs ceil(QUANTITIES[i] / X) stores, so binary search for the smallest X whose total need is at most N.
Input
The first line contains N and M. The second line contains the M quantities.
Output
Print the minimum possible maximum.
Constraints
1 <= M <= N <= 100000; 1 <= QUANTITIES[i] <= 100000
Example input
6 2 11 6
Example output
3
Explanation
With 6 stores and quantities 11 6, give 3 3 3 2 of type 0 to four stores and 3 3 of type 1 to two stores. No store gets more than 3, and 2 would need 6 + 3 = 9 stores.