QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 256 MB مجموع النقاط: 100

#8537. 最大值的最小和

الإحصائيات

Bessie 有 $N$ ($2\le N\le 300$) 块排成一行的瓷砖,其丑陋度分别为 $a_1, a_2, \dots, a_N$ ($1\le a_i\le 10^6$)。其中有 $K$ ($0\le K\le \min(N,6)$) 块瓷砖被固定在原位,具体位置为 $x_1, \dots, x_K$ ($1\le x_1 < x_2 < \dots < x_K\le N$)。

Bessie 想要最小化瓷砖的总丑陋度,总丑陋度定义为每相邻两块瓷砖丑陋度最大值之和,即 $\sum_{i=1}^{N-1}\max(a_i,a_{i+1})$。她可以执行任意次数以下操作:选择两块均未被固定的瓷砖,并交换它们的位置。

请确定 Bessie 在最优操作下能达到的最小总丑陋度。

输入格式

第一行包含 $N$ 和 $K$。

第二行包含 $a_1, \dots, a_N$。

第三行包含 $K$ 个索引 $x_1, \dots, x_K$。

输出格式

输出最小可能的总丑陋度。

样例

样例输入 1

3 0
1 100 10

样例输出 1

110

说明:Bessie 可以交换第二块和第三块瓷砖,使得 $a=[1,10,100]$,从而获得总丑陋度 $\max(1,10)+\max(10,100)=110$。或者,她也可以交换第一块和第二块瓷砖,使得 $a=[100,1,10]$,同样获得总丑陋度 $\max(100,1)+\max(1,10)=110$。

样例输入 2

3 1
1 100 10
3

样例输出 2

110

说明:Bessie 可以交换第一块和第二块瓷砖,使得 $a=[100,1,10]$,获得总丑陋度 $\max(100,1)+\max(1,10)=110$。

样例输入 3

3 1
1 100 10
2

样例输出 3

200

说明:瓷砖的初始总丑陋度为 $\max(1,100)+\max(100,10)=200$。Bessie 只允许交换第一块和第三块瓷砖,这无法使她降低总丑陋度。

样例输入 4

4 2
1 3 2 4
2 3

样例输出 4

9

子任务

  • 输入 5:$K=0$
  • 输入 6-7:$K=1$
  • 输入 8-12:$N\le 50$
  • 输入 13-24:无额外限制

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#119EditorialOpen题解dXqwq2025-12-12 23:08:44View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.