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

25987번 - Heavy Hauling 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 (추가 시간 없음) 2048 MB205466.667%

문제

The warehouse of the Boxes And Parcels Center (BAPC) just received an official warning from the inspector: apparently, it does not conform to the latest safety requirements. In the past, it was allowed to stack multiple boxes at the same shelf location, but due to the potential fire hazard, this is no longer allowed. In a hurry, all employees of the BAPC are roused to move the boxes to distinct positions.

After moving the boxes, the automated parcel retriever robot needs to be reprogrammed such that it knows the correct location of the boxes. Per box that is moved $d$ positions, it takes $d^2$ time to do this reprogramming. Of course, the BAPC should be up and running as soon as possible after moving the boxes, so the boxes should be moved in such a way that this total reprogramming time is as small as possible. Calculate the minimal time for the reprogramming for an optimal moving of boxes.

The warehouse of the BAPC is unbounded in both directions.

As an example, consider Figure H.1, corresponding to the first sample case. One box at position $-1$ is moved to the left, which costs 1ドル$ time for the reprogramming. The box at position 4ドル$ is moved one position to the right, to make place for one of the boxes at position 3ドル,ドル costing 1ドル$ time as well. Two boxes at position 3ドル$ are moved to the left (costing 1ドル$ and 4ドル$), and one box at position 3ドル$ is moved to the right (costing 1ドル$), making the total cost 1ドル+1+1+4+1=8$.

Figure H.1: Visualisation of the first sample case.

입력

The input consists of:

  • One line with an integer $n$ (1ドル\leq n\leq 10^6$), the number of boxes.
  • One line with $n$ integers $x$ ($\left| x \right| \leq 10^9$), the position of each box. The box positions are ordered non-decreasingly.

출력

Output the minimal time to reprogram the parcel retriever robot for an optimal moving of boxes.

제한

예제 입력 1

7
-1 -1 3 3 3 3 4

예제 출력 1

8

예제 입력 2

8
2 2 2 2 2 2 4 4

예제 출력 2

24

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2022 Preliminaries H번

  • 문제를 만든 사람: Ragnar Groot Koerkamp
(追記) (追記ここまで)

출처

대학교 대회

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

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