아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

The Pool for Lucky Ones

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

요약
이웃한 레인 사이로 사람을 한 명씩 옮겨, 최대 인원이 남아 있는 레인의 사람 수 합을 최소로 만든다.
난이도

보통10점 중 6점

유형
그리디, 배열, 시뮬레이션
정답자
아직 제출이 없습니다

문제

A new swimming pool has been built in Kazan for the forthcoming Water Sports World Championship. The pool has NN 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 NN --- the amount of lanes in the pool (3≤N≤1053 \le N \le 10^5). The second line contains NN integers p_ip\_i separated with spaces, describing distribution of swimmers between the lanes where p_ip\_i is the amount of swimmers on ii-th lane (0≤p_i≤1050 \le p\_i \le 10^5).

출력

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

예제2

  1. 예제 1

    입력
    3
    1 3 5
    
    예상 출력
    5
    
  2. 예제 2

    입력
    4
    1 0 1 0
    
    예상 출력
    2