#DSU0000083. Các bình thông nhau – Bản khó (Vessels, Heights and Two Versions, Hard Version)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Các bình thông nhau – Bản khó (Vessels, Heights and Two Versions, Hard Version)
Vessels, Heights and Two Versions (Hard Version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are cylindrical vessels arranged in a circle. Each vessel has a base area of cm and unbounded height. Vessels and are connected at height ; vessel is connected to vessel at height . The connections have negligible volume.
Let be the water level in vessel , where all levels are nonnegative integers. Adjacent vessels can have different levels while the connecting pipe has not been reached. An arrangement is valid exactly when, for every with ,
For each position , independently maximize under the additional restriction . Print one maximum for every choice of the empty vessel.
Input
The first line contains . The second line contains .
Output
Print integers: the -th is the maximum total volume with vessel empty.
Subtasks
- Subtask 1 (20 points): , .
- Subtask 2 (30 points): , .
- Subtask 3 (50 points): , .
Example
Input
4
1 2 3 4
Output
6 6 7 9
Explanation
With vessel empty, has total volume . With vessel empty, has total volume . These are independent scenarios.