#C5089. Number of Moves to Blow Out Candles
Number of Moves to Blow Out Candles
Number of Moves to Blow Out Candles
You are given n candles and their respective heights. In one move, you can blow out all candles that share the maximum height among those that remain lit. Your task is to determine the number of moves required to blow out all the candles.
Formally, let \(H = [h_1, h_2, \dots, h_n]\) represent the heights of the candles. At each move, find \(M = \max\{h_i : h_i \neq 0\}\) and set all \(h_i = 0\) for which \(h_i = M\). The process is repeated until all elements of \(H\) become zero. Output the count of moves performed.
Examples:
- For \(n = 5\) and \(H = [2, 3, 1, 3, 2]\), the number of moves is 3.
- For \(n = 4\) and \(H = [4, 4, 4, 4]\), the number of moves is 1.
inputFormat
The input is given from stdin and consists of:
- An integer n representing the number of candles.
- A line with n space-separated integers representing the heights of the candles.
outputFormat
Output to stdout a single integer representing the number of moves to blow out all the candles.
## sample5
2 3 1 3 2
3