#664
Unrated
Minimum Sum of Maximums
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Bessie has NN (2N3002\le N\le 300) tiles in a line with ugliness values a1,a2,,aNa_1, a_2, \dots, a_N in that order (1ai1061\le a_i\le 10^6). KK (0Kmin(N,6)0\le K\le \min(N,6)) of the tiles are stuck in place; specifically, those at indices x1,,xKx_1,\dots, x_K (1x1<x2<<xKN1\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, i=1N1max(ai,ai+1)\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 NN and KK.

The next line contains a1,,aNa_1,\dots,a_N.

The next line contains the KK indices x1,,xKx_1,\dots,x_K.

출력

Output the minimum possible total ugliness.

예제 입력 1

3 0
1 100 10

예제 출력 1

110

예제 입력 2

3 1
1 100 10
3

예제 출력 2

110

예제 입력 3

3 1
1 100 10
2

예제 출력 3

200

예제 입력 4

4 2
1 3 2 4
2 3

예제 출력 4

9

점수

Input 5: K=0K=0Inputs 6-7: K=1K=1Inputs 8-12: N50N\le 50Inputs 13-24: No additional constraints

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.