## CCO '17 P4 - Rainfall Storage

View as PDF

Points: 20 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

It was a dark and stormy night. It also rained, and rained, and rained.

Lucy wants to capture some of the rain, but she only has limited materials. She has a collection of pillars, of various heights, which she can configure to capture the rain. Each pillar is an integer height and has length and width of . Once Lucy has her configuration of pillars, she has enough other siding material to enclose the front and back to allow rain to fill the all the available space in between pillars. There is more than enough rain and any excess rain will overflow and get absorbed into the earth.

For example, if Lucy has pillars of height , she could configure them as follows (all configurations are illustrated from the side):

 *
*  *
*  *
** *
*****

which would capture units of rain (R) as follows:

 *
*RR*
*RR*
**R*
*****

For this first collection of pillars , she could also capture units of rain as follows:

 *
*RR*
*RR*
**RR*
*****

As another example, if the collection of pillars was , Lucy could capture units of rain as follows:

*R*R*
*R*R*
*R*R*
*R*R*
*****

Finally, this configuration of captures units of rain:

*RRR*
*R*R*
*R*R*
*R*R*
*****

Lucy has pillars with heights . She would like to know, of all possible configurations of pillars, what are all of the obtainable volumes of rainfall that she can capture using these pillars.

#### Input Specification

The first line contains the integer signifying the number of pillars. The next line contains the integers , representing the th pillar height.

For 5 of the 25 marks available, .
For an additional 10 of the 25 marks available, .

#### Output Specification

On one line, output a space-separated list of all possible obtainable integer volumes of rain captured, in increasing order.

#### Sample Input 1

5
1 5 2 1 4

#### Sample Output 1

0 1 2 3 4 5 6 8

#### Explanation for Sample Output 1

This is the first given example.

#### Sample Input 2

5
5 1 5 1 5

#### Sample Output 2

0 4 8

#### Explanation for Sample Output 2

This is the second given example.

#### Sample Input 3

5
5 1 4 1 5

#### Sample Output 3

0 1 3 4 5 6 7 8 9

#### Explanation for Sample Output 3

This is the third given example.