Water Measurement
Problem Statement
You are given a list of containers, each with a specific amount of water. You need to measure the water in a series of rounds. In each round, you find the smallest non-zero amount of water and reduce all containers with water by that amount. At the end of each round, record how many containers still have water. Continue until all containers are empty.
Input Format
- The first line contains an integer, , the number of containers.
- The second line contains space-separated integers, representing the water levels in the containers.
Output Format
- Print the number of containers still containing water after each round.
Constraints
Sample Input 1
Sample Output 1
Explanation 1
- Initial water levels: [5, 1, 2, 3, 4]
- Smallest non-zero: 1 → Subtract 1 → Remaining: [4, 0, 1, 2, 3] → Count: 5
- Smallest non-zero: 1 → Subtract 1 → Remaining: [3, 0, 0, 1, 2] → Count: 4
- Smallest non-zero: 1 → Subtract 1 → Remaining: [2, 0, 0, 0, 1] → Count: 3
- Smallest non-zero: 1 → Subtract 1 → Remaining: [1, 0, 0, 0, 0] → Count: 2
- Smallest non-zero: 1 → Subtract 1 → Remaining: [0, 0, 0, 0, 0] → Count: 1
Sample Input 2
Sample Output 2
Explanation 2
- Initial water levels: [8, 3, 6, 7, 7, 3]
- Smallest non-zero: 3 → Subtract 3 → Remaining: [5, 0, 3, 4, 4, 0] → Count: 6
- Smallest non-zero: 2 → Subtract 2 → Remaining: [2, 0, 0, 1, 1, 0] → Count: 4
- Smallest non-zero: 1 → Subtract 1 → Remaining: [1, 0, 0, 0, 0, 0] → Count: 3
- Smallest non-zero: 1 → Subtract 1 → Remaining: [0, 0, 0, 0, 0, 0] → Count: 1
Python Code
Comments
Post a Comment