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

32564번 - Eradication Sort 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB39241862.069%

문제

The members of the No-Weather-too-Extreme Recreational Climbing society completed their first successful summit seven years ago to this day!

At the time, we took a picture of all the members standing together in one row. However, the photograph looks messy, as the climbers were not standing in order of height, and we have no way to reorder them.

We will need to cut some of the climbers out of the picture.

Figure E.1: This picture of 7 (formerly 11) climbers was edited to solve Sample Input 3.

An optimal solution minimises the size and number of visible gaps in the photo. We define the cost as the sum of the squares of the lengths of gaps left in the edited photo. For example, if two individual climbers are removed from the photo and one pair of adjacent climbers are removed, the total cost is 1ドル^2 + 1^2 + 2^2 = 6$.

Find the minimum possible cost you can reach by removing climbers.

입력

  • The number of people in the photo $n$ (1ドル \le n \le 10^6$).
  • $n$ integers representing the heights of people in the photo, $h_1 \ldots h_n$ (0ドル \le h \le 10^6$).

출력

Output the minimum cost achieved by removing climbers from the photo, such that the remaining climbers in the photo make a non-decreasing sequence.

제한

예제 입력 1

7
1 2 3 0 5 6 7

예제 출력 1

1

예제 입력 2

9
4 5 6 4 2 3 6 6 6

예제 출력 2

8

예제 입력 3

11
3 6 12 7 7 7 6 8 10 5 5

예제 출력 3

6

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > The UK & Ireland Programming Contest > UKIEPC 2024 E번

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

출처

대학교 대회

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

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