P27653 [洛谷] [USACO24FEB] Minimum Sum of Maximums P
省选
题目描述

Problem Description

Bessie has a row of $N$ ($2 \le N \le 300$) tiles, each with an ugliness value $a_1, a_2, \ldots, a_N$ ($1 \le a_i \le 10^6$). Among these, $K$ ($0 \le K \le \min(N, 6)$) tiles are stuck; specifically, the tiles at indices $x_1, \ldots, x_K$ ($1 \le x_1 < x_2 < \cdots < x_K \le N$).

Bessie wants to minimize the total ugliness of the tiles, where the total ugliness is defined as the sum of the maximum ugliness between each pair of adjacent tiles; that is, $\sum_{i=1}^{N-1} \max(a_i, a_{i+1})$. She can perform the following operation any number of times: choose two tiles that are not stuck and swap them.

Determine the minimum total ugliness that Bessie can achieve by performing operations optimally.

Input Format

The first line of input contains $N$ and $K$.

The second line contains $a_1, \ldots, a_N$.

The third line contains $K$ indices $x_1, \ldots, x_K$.

Output Format

Output the minimum possible total ugliness.

Sample Input and Output

Sample Input #1

3 0
1 100 10

Sample Output #1

110

Sample Input #2

3 1
1 100 10
2

Sample Output #2

200

Sample Input #3

4 2
1 3 2 4
2 3

Sample Output #3

9

Notes

Sample Explanation 1

Bessie can swap the second and third tiles, resulting in $a = [1, 10, 100]$, achieving a total ugliness of $\max(1, 10) + \max(10, 100) = 110$. Alternatively, she can swap the first and second tiles, resulting in $a = [100, 1, 10]$, which also achieves a total ugliness of $\max(100, 1) + \max(1, 10) = 110$.

Sample Explanation 2

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.

Test Case Properties

  • Test case $5$: $K = 0$.
  • Test cases $6-7$: $K = 1$.
  • Test cases $8-12$: $N \le 50$.
  • Test cases $13-24$: No additional restrictions.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 0 1 100 10
样例输出
110