문제
Bessie has () tiles in a line with ugliness values in that order (). () of the tiles are stuck in place; specifically, those at indices ().
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, . 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 and .
The next line contains .
The next line contains the indices .
출력
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: Inputs 6-7: Inputs 8-12: Inputs 13-24: No additional constraints
코드를 제출하려면 로그인이 필요합니다.
로그인