#P10194. Circular Milk Passing
Circular Milk Passing
Circular Milk Passing
Farmer John's () cows are arranged in a circle. The -th cow has a bucket with an integer capacity () liters, and initially every bucket is full. Every minute, all cows simultaneously pass all the milk in their bucket to the next cow in clockwise order: for , cow sends her milk to cow , and cow sends her milk to cow . After receiving the milk, each cow retains milk up to the capacity of her bucket, and any excess is spilled and lost.
Formally, let denote the milk in cow initially. Then for each minute , the milk in cow is updated as follows: [ x_1(t)=\min\Bigl(a_1,;x_{N}(t-1)\Bigr),\quad x_i(t)=\min\Bigl(a_i,;x_{i-1}(t-1)\Bigr)\quad(2\le i\le N). ] Note that this is equivalent to saying that after minutes, cow holds [ x_i(t)=\min\Bigl{a_i, a_{i-1},\dots, a_{i-t}\Bigr}, ] where the indices are taken modulo (with the obvious adjustment when , since the circle has only cows).
Your task is to compute, for each minute , the total amount of milk remaining among all cows, i.e. compute [ S(t)=\sum_{i=1}^N x_i(t). ]
Input Format: The first line contains an integer . The second line contains space‐separated integers , which are the capacities of the buckets in clockwise order.
Output Format: Output lines. The -th line (for ) should contain a single integer, the value of after minutes.
Note: Although can be large (up to ) and the capacities can be as large as , the process quickly propagates the minimum value around the circle. For the purposes of this problem and the provided test cases, however, you may assume that a simulation with iterations is sufficient.
inputFormat
Input Format:
- The first line contains an integer $N$.
- The second line contains $N$ space‐separated integers $a_1,a_2,\dots,a_N$.
outputFormat
Output Format:
- Output $N$ lines. The $t$-th line (for $1\le t\le N$) contains the total amount of milk remaining after $t$ minutes.
sample
4
5 7 3 6
16
14
12
12
</p>