#P10197. Minimizing Tile Ugliness Sum
Minimizing Tile Ugliness Sum
Minimizing Tile Ugliness Sum
Bessie has a row of \(N\) tiles (\(2 \le N \le 300\)) with ugliness values \(a_1, a_2, \ldots, a_N\) (\(1 \le a_i \le 10^6\)). However, \(K\) tiles are blocked (\(0 \le K \le \min(N,6)\)). The indices of the blocked tiles are \(x_1, x_2, \ldots, x_K\) (with \(1 \le x_1 < x_2 < \cdots < x_K \le N\)).
Bessie wants to minimize the total ugliness of the row. The total ugliness is defined as
[ S = \sum_{i=1}^{N-1} \max(a_i, a_{i+1}). ]
She is allowed to perform the following operation any number of times:
- Choose any two unblocked tiles and swap them.
This means that Bessie can arbitrarily reorder the unblocked tiles while the blocked tiles remain fixed. Determine the minimum total ugliness \(S\) that can be achieved.
inputFormat
The first line contains two integers \(N\) and \(K\). The second line contains \(N\) integers \(a_1, a_2, \ldots, a_N\). If \(K > 0\), the third line contains \(K\) distinct integers \(x_1, x_2, \ldots, x_K\) in increasing order indicating the positions of the blocked tiles.
outputFormat
Output one integer: the minimal possible total ugliness \(S\) after optimally reordering the unblocked tiles.
sample
3 1
100 1 200
2
300