PDP-38 (2026) - Phase A - 1 (bamboo)

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
Blockly, C, C++, Java, Pascal, Python

Bamboo 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 N bamboo plants in the garden. Their heights are denoted by the positive integers h_1, h_2, ..., h_N. 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:

  1. He records the maximum height H among all his bamboo plants.
  2. He then cuts down all the bamboo plants whose height is H (that is, he sets their height to zero).

If, after this step, all N bamboo plants have zero height, he stops. Otherwise, he waits until the next day and repeats the process starting from step 1.

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 N: the number of bamboo plants in Takis's garden.

The second line contains N integers h_1, h_2, ..., h_N: 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 1: The maximum height is 7. Therefore, Takis cuts down the 2-nd and 4-th bamboo plants.

  • Day 2: The maximum height is now 3. Therefore, Takis cuts down the 3-rd and 5-th bamboo plants.

  • Day 3: The maximum height is 1. Takis cuts down the 1-st bamboo plant, and now all the bamboo plants have been cut down, so he stops.

Therefore, Takis would need 3 days.

Constraints
  • 1 \le N \le 200.000
  • 1 \le h_i \le 10^9
Subtasks
  1. (13 points) N = 2
  2. (17 points) All bamboo plants have distinct heights.
  3. (19 points) N \le 5.000
  4. (23 points) h_i \le 10^5 for every i (where 1 \le i \le N).
  5. (28 points) There are no further restrictions.
Notes
  • Formatting: In both the input and the output, each line ends with a newline character.
  • Maximum execution time: 1 sec.
  • Maximum available memory: 64 MB.

Warning: The answer may exceed 2^{32} 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

There are no comments at the moment.