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

16185번 - Fascination Street 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB109585358.242%

문제

A street named Fascination Street is divided into $N$ equal length of blocks. For each block $i$ (1ドル \leq i \leq N$), it has block $i-1$ in its left side if $i > 1,ドル and block $i+1$ in its right side if $i < N$.

Unlike its name, the street is infamous to be a dark and eerie place in the night. To solve this, Robert decided to install the streetlight for some of the blocks. The cost of installing a streetlight for $i$-th block is $W_i,ドル and the total cost is the sum of each installation cost. After installing, every block should either have a streetlight, or have a streetlight in its left or right block.

Robert also has some tricks to reduce the cost. Before installing the streetlight, Robert selects two distinct blocks $i$ and $j,ドル and exchange their position. After the operation, the cost of installation is exchanged. In other words, the operation simply swaps the value of $W_i$ and $W_j$. This operation have no cost, but Robert can only perform it at most $K$ times.

Now, given the array $W$ and the maximum possible number of operations $K,ドル you should find the minimum cost of lighting the whole street.

입력

The first line contains two space-separated integers $N,\ K$. $N$ is the number of blocks, and $K$ is the maximum possible number of operations. (1ドル \leq N \leq 250000, \ 0 \leq K \leq 9$)

The second line contains $N$ space-separated integers $W_1,ドル $W_2,ドル $\cdots,ドル $W_N,ドル where $W_i$ is the cost of installing a streetlight for $i$-th block. (0ドル \leq W_i \leq 10^9$)

출력

Print a single integer which contains the minimum cost of lighting the whole street.

제한

예제 입력 1

5 0
1 3 10 3 1

예제 출력 1

4

예제 입력 2

5 1
1 3 10 3 1

예제 출력 2

2

예제 입력 3

12 0
317 448 258 208 284 248 315 367 562 500 426 390

예제 출력 3

1525

예제 입력 4

12 2
317 448 258 208 284 248 315 367 562 500 426 390

예제 출력 4

1107

힌트

출처

University > KAIST > KAIST ICPC Mock Competition > 2018 KAIST 8th ACM-ICPC Mock Competition E번

Contest > Open Cup > 2018/2019 Season > Stage 5: Grand Prix of Korea G번

  • 문제를 만든 사람: koosaga
  • 문제의 오타를 찾은 사람: jh05013
(追記) (追記ここまで)

출처

대학교 대회

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

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