Logo
(追記) (追記ここまで)

22266번 - Crisis at the Wedding 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB92545160.000%

문제

A famous football player just got married and is holding a party for his wedding guests. The guests are seated at tables around a circular pond in the garden of the player’s villa. Each table accommodates exactly the same number of guests, and consecutive tables around the pond are at a unit distance.

At the moment of the traditional Best Man toast a crisis erupted: although the total number of champagne glasses in the guests’ tables is exactly the number of guests, the glasses could have been distributed unevenly over the tables, with some tables having more glasses than guests and some other tables having fewer glasses than guests.

A single waiter is available to fix the glasses distribution, collecting surplus glasses from tables and delivering them to tables needing glasses. The cost of each glass fix is the distance the waiter carries the glass until he delivers it to a table. The total cost for the operation is the sum of the costs for all glasses. The waiter can start at any table, but the player is superstitious and will only allow the waiter to walk in a strict clockwise or counterclockwise direction when fixing the glasses distribution. That is, once the waiter starts in one direction (clockwise or counterclockwise) he cannot change the direction.

Earn an autographed jersey from the football player by helping him to calculate the smallest possible total cost for fixing the glasses distribution.

입력

The first line contains an integer $N$ (1ドル \le N \le 10^5$) indicating the number of tables around the circular pond. The second line contains $N$ integers $G_1, G_2, \dots ,G_N$ (0ドル \le G_i \le 1000$ for $i = 1, 2, \dots , N$), representing the number of glasses in the different tables. These numbers are given in clockwise order. It is guaranteed that $N$ divides $\sum_{i=1}^{N}{G_i}$.

출력

Output a single line with an integer indicating the smallest possible total cost for fixing the glasses distribution.

제한

예제 입력 1

4
14 10 6 10

예제 출력 1

8

예제 입력 2

6
24 122 0 37 49 242

예제 출력 2

454

예제 입력 3

6
0 0 0 0 60 0

예제 출력 3

150

예제 입력 4

1
0

예제 출력 4

0

힌트

출처

ICPC > Regionals > Latin America > Latin America Regional Contests > Latin America Regional Contests 2020 C번

  • 문제를 만든 사람: Ricardo Anido
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /