Milk Exchange

시간 제한2초메모리 제한1024 MB

요약
원형으로 배치된 소들이 매분 시계 방향으로 우유를 전부 넘기고 용량을 넘는 양은 버려질 때, 1분부터 N분까지 남은 우유의 총량을 구한다.
난이도

어려움10점 중 8점

유형
그리디, 배열, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

Farmer John's NN (1≤N≤5⋅105)(1 \leq N \leq 5 \cdot 10^5) cows are lined up in a circle. The iith cow has a bucket with integer capacity a_ia\_i (1≤a_i≤109)(1 \leq a\_i \leq 10^9) liters. All buckets are initially full.

Every minute, cow ii will pass all the milk in their bucket to cow i+1i+1 for 1≤i\<N1\le i\<N, with cow NN passing its milk to cow 11. All exchanges happen simultaneously (i.e., if a cow has a full bucket but gives away xx liters of milk and also receives xx liters, her milk is preserved). If a cow's total milk ever ends up exceeding a_ia\_i, then the excess milk will be lost.

After each of 1,2,…,N1, 2, \dots, N minutes, how much total milk is left among all cows?

입력

The first line contains NN.

The next line contains integers a_1,a_2,...,a_Na\_1,a\_2,...,a\_N.

출력

Output NN lines, where the ii-th line is the total milk left among all cows after ii minutes.

예제3

  1. 예제 1

    입력
    6
    2 2 2 1 2 1
    
    예상 출력
    8
    7
    6
    6
    6
    6
    
  2. 예제 2

    입력
    8
    3 8 6 4 8 3 8 1
    
    예상 출력
    25
    20
    17
    14
    12
    10
    8
    8
    
  3. 예제 3

    입력
    10
    9 9 10 10 6 8 2 1000000000 1000000000 1000000000
    
    예상 출력
    2000000053
    1000000054
    56
    49
    42
    35
    28
    24
    20
    20