Universal Cup Judging System

Universal Cup

Time Limit: 4 s Memory Limit: 2048 MB Total points: 100 Difficulty: [show] Hackable ✓
Statistics

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.