#PU1405. USACO 2024 February Contest, Platinum — Problem 2. Minimum Sum of Maximums
USACO 2024 February Contest, Platinum — Problem 2. Minimum Sum of Maximums
USACO 2024 February Contest, Platinum — Problem 2. Minimum Sum of Maximums
题目描述
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 .
输出格式
(见题面原文)
数据范围
(见题面原文)
样例
样例 1
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$.
样例 2
3 1
1 100 10
3
110
Bessie could swap the first and second tiles so that $a=[100,1,10]$, achieving
total ugliness $\max(100,1)+\max(1,10)=110$.
样例 3
3 1
1 100 10
2
200
The initial total ugliness of the tiles is $\max(1,100)+\max(100,10)=200$.
Bessie is only allowed to swap the first and third tiles, which does not allow
her to reduce the total ugliness.
样例 4
4 2
1 3 2 4
2 3
9