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.