페이지가 로드되지 않나요? 여기를 눌러보면 고쳐질 수도 있어요.
Placeholder

#8150
서브태스크

Minimum Sum of Maximums 1s 1024MB

문제

Bessie has N (2\le N\le 300) tiles in a line with ugliness values a_1, a_2, \dots, a_N in that order (1\le a_i\le 10^6). K (0\le K\le \min(N,6)) of the tiles are stuck in place; specifically, those at indices x_1,\dots, x_K (1\le x_1 < x_2<\dots< x_K\le N).

Bessie wants to minimize the total ugliness of the tiles, which is defined as the sum of the maximum ugliness over every consecutive pair of tiles; that is, \sum_{i=1}^{N-1}\max(a_i,a_{i+1}). She is allowed to perform the following operation any number of times: choose two tiles, neither of which are stuck in place, and swap them.

Determine the minimum possible total ugliness Bessie can achieve if she performs operations optimally.


입력

The first line contains N and K.

The next line contains a_1,\dots,a_N.

The next line contains the K indices x_1,\dots,x_K.


출력

Output the minimum possible total ugliness.


부분문제

번호 점수 조건
#110점

K=0

#220점

K=1

#330점

N \le 50

#440점

추가 제약 조건 없음


예제

3 0
1 100 10
110

Bessie can swap the second and third tiles so that a=[1,10,100], achieving total ugliness

\max(1,10)+\max(10,100)=110. Alternatively, she could swap the first and second tiles so that a=[100,1,10], also achieving total ugliness \max(100,1)+\max(1,10)=110.


출처

USACO 2024 February Platinum 2번

로그인해야 코드를 작성할 수 있어요.