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

8107번 - Boxes 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB219583.333%

문제

There are n boxes on the circle. The boxes are numbered from 1 to n (1 ≤ n ≤ 1,000) in clockwise order. There are balls in the boxes, and the number of all the balls in the boxes is not greater than n. The balls should be displaced in such a way that in each box there remains no more than one ball. In one move we can shift a ball from one box to one of it's neighboring boxes.

Write a program that:

  • reads from the standard input the number of boxes n and the arrangement of balls in the boxes,
  • computes the minimal number of moves necessary to displace the balls in such a way that in each box there remains no more than one ball,
  • writes the result to the standard output.

입력

In the first line of the standard input there is written one positive integer n — the number of boxes. In each of the following n lines there is written one nonnegative integer. In the i-th of these lines there is written the number of balls in the i-th box.

출력

Your program should write to the standard output one nonnegative integer — the number of moves necessary to displace the balls in such a way that in each box there remains no more than one ball.

제한

예제 입력 1

12
0
0
2
4
3
1
0
0
0
0
0
1

예제 출력 1

19

힌트

출처

Olympiad > Polish Olympiad in Informatics > POI 1995/1996 > Stage 3 2번

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

출처

대학교 대회

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

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