#P1027. Problem 2. Minimum Sum of Maximums
Problem 2. Minimum Sum of Maximums
当前没有测试数据。
一、Problem Name
Minimum Sum of Maximums
二、Problem 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 (input arrives from the terminal / stdin)
- The first line contains and .
- The next line contains .
- The next line contains the indices .
四、Output Format (print output to the终端 / stdout)
Output the minimum possible total ugliness.
五、Sample Input and Output
Sample Input 1
3 0
1 100 10
Sample Output 1
110
Explanation: 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 .
Sample Input 2
3 1
1 100 10
3
Sample Output 2
110
Explanation: Bessie could swap the first and second tiles so that , achieving total ugliness .
Sample Input 3
3 1
1 100 10
2
Sample Output 3
200
Explanation: 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.
Sample Input 4
4 2
1 3 2 4
2 3
Sample Output 4
9
六、Scoring Rules
- Input 5: .
- Inputs 6 - 7: .
- Inputs 8 - 12: .
- Inputs 13 - 24: No additional constraints.
Problem credits: Benjamin Qi.