#P10197. [USACO24FEB] Minimum Sum of Maximums P
[USACO24FEB] Minimum Sum of Maximums P
Description
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.
Input Format
The first line contains and .
The next line contains .
The next line contains the indices .
Output Format
Output the minimum possible total ugliness.
3 0
1 100 10
110
3 1
1 100 10
2
200
4 2
1 3 2 4
2 3
9
3 1
1 100 10
3
110
Hint
For Sample 1:
Bessie can swap the second and third tiles so that , achieving total ugliness . Alternatively, she could swap the first and second tiles so that , also achieving total ugliness .
For Sample 2:
Bessie could swap the first and second tiles so that , achieving total ugliness .
For Sample 3:
The initial total ugliness of the tiles is . Bessie is only allowed to swap the first and third tiles, which does not allow her to reduce the total ugliness.
SCORING:
- Input 5:
- Inputs 6-7:
- Inputs 8-12:
- Inputs 13-24: No additional constraints
京公网安备 11011102002149号