Rearrange the pebbles in each step so that as many piles as possible are painted, subject to a fixed per-step painting limit.
Problem
You are given several piles of pebbles. In one operation, you may choose a fixed amount of pebbles to paint from the available piles, but each pile can contribute only a limited number of pebbles to the painted set in that step. The goal is to determine the minimum number of operations needed to paint all pebbles, or equivalently the maximum progress possible per operation under the restriction.
More concretely, each pile has a size, and in every step you can reduce the sizes of some piles while keeping the process valid. You must decide the best order of selecting piles so that the total number of required steps is minimized.
This is an implementation-heavy greedy problem: the key is to always use the most useful available piles first and keep track of how many piles remain active after each step.
Input Format
- The input consists of one test case.
- The first line contains an integer — the number of piles.
- The second line contains integers describing the pile sizes.
Output Format
- Print one integer: the minimum number of operations needed to finish the process described in the problem.
- If multiple optimal strategies exist, any one of them is acceptable as long as the count is minimal.
Constraints
- Pile sizes are positive integers
- Time complexity should be close to linear or
Example 1
Input
5 1 2 2 3 3
Output
3
Explanation
A valid greedy schedule can reduce the tallest useful piles first. The total process finishes in 3 steps under the given restriction.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.