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

31367번 - The Pool for Lucky Ones 다국어

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

문제

A new swimming pool has been built in Kazan for the forthcoming Water Sports World Championship. The pool has $N$ lanes. Some of the lanes are already occupied by swimmers. Tatar scientists have divided the lanes into the lucky and unlucky ones. The unlucky lanes are those with the maximum amount of swimmers. That is, there is no other lane where there would be more swimmers than on unlucky one. The unlucky lanes make swimmers unhappy. The rest of the lanes are considered to be lucky. The lucky lanes make people happy. The scientists took a decision to make more people happy. In order to do this they had an agreement with the pool manager saying they can move a single person from any lane to the one neighboring if it was necessary. The swimmer from the first lane can only be moved to the second lane, and the swimmer from the last lane --– to the one before last.

입력

The first line contains an integer $N$ --- the amount of lanes in the pool (3ドル \le N \le 10^5$). The second line contains $N$ integers $p_i$ separated with spaces, describing distribution of swimmers between the lanes where $p_i$ is the amount of swimmers on $i$-th lane (0ドル \le p_i \le 10^5$).

출력

Output a single number --- minimal possible number of unhappy swimmers.

제한

예제 입력 1

3
1 3 5

예제 출력 1

5

예제 입력 2

4
1 0 1 0

예제 출력 2

2

힌트

출처

Contest > Open Cup > 2014/2015 Season > Stage 11: Grand Prix of Tatarstan > Division 1 L번

Contest > Open Cup > 2014/2015 Season > Stage 11: Grand Prix of Tatarstan > Division 2 L번

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

출처

대학교 대회

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

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