#P6726. [COCI 2015/2016 #5] POPLAVA
[COCI 2015/2016 #5] POPLAVA
Description
There is a histogram consisting of columns. From left to right, the heights of the columns are .
Now you need to pour water into it. The capacity of the histogram is defined as the maximum amount of water it can store when the water structure is “stable”, i.e. the water will not flow under gravity. The figure below shows a stable example.

More specifically, let the water height on each column from left to right be . Let . It is a stable state when the following conditions are satisfied:
-
For any , when , we have .
-
For any , when , we have .
-
.
Now you need to choose a permutation of as the heights of the columns such that the capacity of the histogram is . If it does not exist, output -1. If there are multiple solutions, output any one.
Input Format
Input one line with two integers .
Output Format
If no solution exists, output -1.
Otherwise output one line with integers, . Output any valid solution. This problem uses SPJ.
3 1
3 1 2
4 1
4 3 1 2
8 17
6 2 3 1 8 4 5 7
Hint
Sample Explanation
Sample
.
Sample
.
Sample
This sample corresponds to the figure in the statement.
Constraints
For of the testdata, , .
Note
Translated from COCI2015-2016 CONTEST #5 T4 POPLAVA.
Translated by ChatGPT 5
京公网安备 11011102002149号