#P6345. [CCO 2017] 接雨滴
[CCO 2017] 接雨滴
Description
At night, it is pitch-dark and windy, and heavy rain is pouring down from the sky.
Lucy wants to catch some raindrops, but she only has limited tools. She has a set of pillars of different heights to catch raindrops. Each pillar has an integer height and width . After she arranges the pillars, she will use other tools to clamp them together, so that raindrops can be stored smoothly in the gaps between the pillars. You may assume the amount of rain is infinite.
For example, if Lucy has five pillars with heights , she can arrange them like this:
*
* *
* *
** *
*****
This will catch raindrops ( represents one unit of raindrops).
For convenience, we define as the unit of raindrops.
*
*RR*
*RR*
**R*
*****
Of course, she can also arrange them like this, which will catch raindrops:
*
*RR*
*RR*
**RR*
*****
As another example, if the pillar heights are , Lucy can catch raindrops:
*R*R*
*R*R*
*R*R*
*R*R*
*****
In the last example, if the pillar heights are , she can catch raindrops:
*RRR*
*R*R*
*R*R*
*R*R*
*****
Lucy has pillars with heights . She wants to know, among all possible arrangements, all possible amounts of raindrops that can be caught (measured in units of ). (See the sample explanation for details.)
Input Format
The first line contains an integer , the number of pillars.
The second line contains integers , the heights of the pillars.
Output Format
Output a single line. Print all possible numbers of raindrops that can be caught (in units of ) in increasing order.
5
1 5 2 1 4
0 1 2 3 4 5 6 8
5
5 1 5 1 5
0 4 8
5
5 1 4 1 5
0 1 3 4 5 6 7 8 9
Hint
Sample Explanation
See the three examples above.
Constraints and Notes
This problem uses bundled testdata, with a total of subtasks.
- Subtask 1 (20 points): .
- Subtask 2 (40 points): .
- Subtask 3 (40 points): , .
For all testdata, it is guaranteed that and .
Source: CCO 2017 Day 2 “Rainfall Capture”.
Note: This translation is from LOJ.
Translated by ChatGPT 5
京公网安备 11011102002149号