AmazonOA #258
Max Batches For Shipment
Estimated HardJudge-ready
Topics (AI-labelled)GreedyIn-place Arrays
Each category has inventory[i] items. Each batch uses at most one item per category, and each batch must contain strictly more items than the previous one; each item can be used at most once, and leftovers are allowed. Find the maximum number of batches.
Input
The first line contains n; the second line contains the inventories. The original text had no numeric bounds; this site uses 1≤n≤200000, 0≤inventory[i]≤10^9.
Output
Output a single integer, the answer.
Example 1
Input:
5
2 3 1 4 2
Output:
4
Example 2
Input:
3
100 1 1
Output:
2
Example 3
Input:
3
0 0 0
Output:
0
Example notes
The answers are 4, 2 and 0. Even with a large total, the two of the three categories that have only one item each cannot both supply the second and the third batches.
Editorial
Loading solution…