PDP-38 (2026) - Phase A - 1 (bamboo)
View as PDFBamboo Garden
Takis has a small garden that he takes care of to relax and get away from the stress of working at the pizzeria.
There are bamboo plants in the garden.
Their heights are denoted by the positive integers
,
,
,
.
Takis is tired of having so many bamboo plants in his garden and wants to cut them down.
To do so, he follows the procedure below:
- He records the maximum height
among all his bamboo plants.
- He then cuts down all the bamboo plants whose height is
(that is, he sets their height to zero).
If, after this step, all bamboo plants have zero height, he stops.
Otherwise, he waits until the next day and repeats the process starting from step
.
As a good friend of Takis, you are worried that this process might require him to spend many years cutting down bamboo plants. Therefore, to convince him to reconsider, you want to determine how many days he would need in total to complete this process.
Problem
Write a C++ program that reads the input data from bamboo.in and writes the results to bamboo.out.
Input Files (bamboo.in)
The first line contains an integer : the number of bamboo plants in Takis's garden.
The second line contains integers
,
,
,
: the heights of the bamboo plants.
Output Files (bamboo.out)
The output must contain a single line with an integer: the number of days Takis would need to cut down all the plants in his garden using the procedure described above.
Sample Input and Output Files
Input:
5
1 7 3 7 3
Output:
3
Explanation:
Takis would cut down his bamboo plants as follows:
Day
: The maximum height is
. Therefore, Takis cuts down the
-nd and
-th bamboo plants.
Day
: The maximum height is now
. Therefore, Takis cuts down the
-rd and
-th bamboo plants.
Day
: The maximum height is
. Takis cuts down the
-st bamboo plant, and now all the bamboo plants have been cut down, so he stops.
Therefore, Takis would need days.
Constraints
Subtasks
- (13 points)
- (17 points) All bamboo plants have distinct heights.
- (19 points)
- (23 points)
for every
(where
).
- (28 points) There are no further restrictions.
Notes
- Formatting: In both the input and the output, each line ends with a
newlinecharacter. - Maximum execution time:
sec.
- Maximum available memory:
MB.
Warning: The answer may exceed and, in general, you may need to perform operations with numbers larger than those that can be represented by the basic
int type.
Also, make sure to read the input and print the output efficiently in problems that require it.
Comments