Fascination Street

모든 블록이 자기 자신이나 이웃 블록의 가로등으로 덮이도록 가로등을 설치할 블록을 고르되, 설치 비용 배열의 두 원소를 최대 K번 교환한 뒤 총비용이 최소가 되게 한다.

어려움8동적 계획법그리디정렬완전 탐색아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

A street named Fascination Street is divided into NN equal length of blocks. For each block ii (1iN1 \leq i \leq N), it has block i1i-1 in its left side if i>1i > 1, and block i+1i+1 in its right side if i<Ni < 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 ii-th block is W_iW\_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 ii and jj, and exchange their position. After the operation, the cost of installation is exchanged. In other words, the operation simply swaps the value of W_iW\_i and W_jW\_j. This operation have no cost, but Robert can only perform it at most KK times.

Now, given the array WW and the maximum possible number of operations KK, you should find the minimum cost of lighting the whole street.

입력

The first line contains two space-separated integers N, KN,\ K. NN is the number of blocks, and KK is the maximum possible number of operations. (1N250000, 0K91 \leq N \leq 250000, \ 0 \leq K \leq 9)

The second line contains NN space-separated integers W_1W\_1, W_2W\_2, \cdots, W_NW\_N, where W_iW\_i is the cost of installing a streetlight for ii-th block. (0W_i1090 \leq W\_i \leq 10^9)

출력

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