Universal Cup Judging System

Universal Cup

时间限制: 4 s 内存限制: 2048 MB 总分: 100 难度: [显示] 可 Hack ✓
统计

The Universe of Cup 是小青魚居住的地方。在這個宇宙中最大的行星 Rainbow-Earth 上,萬物都被塗成了 $k$ 種顏色之一,顏色從 $1$ 到 $k$ 編號。小青魚有 $n$ 個物品,第 $i$ 個物品的顏色為 $a_i$,價值為 $b_i$。

作為執行長,小青魚正在為第四屆 Universal Cup 總決賽(The 4th Universal Cup Finals)的參賽選手準備歡迎禮物。他熱愛多彩的世界,因此他想要恰好選擇 $k$ 個物品,每種顏色各一個。

出於某種原因(也許是因為他喜歡這個詞,又或許只是因為他不知道還能問你什麼),小青魚將一種選擇方案的得分定義為所有被選中物品的無序對之間價值差的絕對值之和。形式化地說,對於所選索引集合 $S \subseteq \{1, 2, \ldots, n\}$,滿足 $|S| = k$ 且 $\{a_i \mid i \in S\} = \{1, 2, \ldots, k\}$,其得分為 $$\sum_{\substack{i,j \in S \\ i < j}} |b_i - b_j|.$$

請找出可能的最大得分。

輸入格式

第一行包含兩個整數 $n$ 和 $k$($1 \le n \le 2 \times 10^5$,$1 \le k \le \min(n, 2000)$),分別表示物品的數量與顏色的數量。

第二行包含 $n$ 個整數 $a_1, a_2, \ldots, a_n$($1 \le a_i \le k$),其中 $a_i$ 表示第 $i$ 個物品的顏色。

第三行包含 $n$ 個整數 $b_1, b_2, \ldots, b_n$($0 \le b_i \le 10^9$),其中 $b_i$ 表示第 $i$ 個物品的價值。

保證從 $1$ 到 $k$ 的每個整數在陣列 $a$ 中都至少出現一次。

輸出格式

輸出一行一個整數,表示可能的最大得分。

範例

輸入格式 1

4 2
1 1 2 2
0 2 1 3

輸出格式 1

3

輸入格式 2

6 3
1 2 1 3 2 3
1 7 9 4 2 6

輸出格式 2

14

輸入格式 3

8 4
1 1 2 2 3 3 4 4
0 1 0 1 0 1 0 1

輸出格式 3

4

說明

在第一組範例測試資料中,小青魚可以選擇索引 $1$ 和 $4$,得分為 $|0 - 3| = 3$。

在第二組範例測試資料中,選擇索引 $3$、$5$ 和 $4$ 可以得到價值 $9$、$2$ 和 $4$,得分為 $|9 - 2| + |9 - 4| + |2 - 4| = 14$。

在第三組範例測試資料中,小青魚可以從每種顏色中各選一個物品,使得選出的價值分別為 $0$、$0$、$1$ 和 $1$。四個價值不同的無序對各自貢獻 $1$,因此最大得分為 $4$。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#3047EditorialOpenNew Editorial for Problem #22887qoj0923View
#3052EditorialOpenNew Editorial for Problem #22887ucup-team7455View

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.