#DSU0000080. Các bình thông nhau (Vessels, Heights and Two Versions – Easy Version)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Các bình thông nhau (Vessels, Heights and Two Versions – Easy Version)
Vessels, Heights and Two Versions (Easy Version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are vessels arranged in a circle and numbered from to . Every vessel has unlimited height and base area cm.
Vessel is connected to vessel by a pipe at height cm, and vessel is connected to vessel at height . Pipe volumes are negligible. If the water level in either neighboring vessel exceeds the pipe's height, the water levels in both vessels must be equal.
Let denote the non-negative integer water level of vessel , also equal to its water volume in cm. A configuration is valid if the following holds for every , with :
For each from to , independently consider the condition that vessel is empty, i.e. . Determine the maximum total water volume in all vessels for that condition.
Each empty-vessel choice is a separate scenario; water configurations are not carried over between scenarios.
Input
- The first line contains the integer .
- The second line contains integers .
Output
Print integers on one line. The -th integer is the maximum total water volume if vessel is empty.
Subtasks
- Subtask 1 (20 points): , .
- Subtask 2 (30 points): , .
- Subtask 3 (50 points): , .
Examples
Input
4
1 2 3 4
Output
6 6 7 9
Explanation
When vessel must be empty, water levels give a total volume of .
When vessel must be empty, an optimal configuration is , totaling .
When vessel must be empty, levels give a total of . Adding more water would violate at least one pipe constraint.