CF999F Cards and Joy
题目描述
有 $n$ 个玩家坐在桌子旁。每个玩家都有一个喜欢的数字。第 $j$ 个玩家的喜欢数字是 $f_j$。
桌子上有 $k \cdot n$ 张卡牌。每张卡牌都包含一个整数:第 $i$ 张卡牌包含数字 $c_i$。此外,您还会得到一个序列 $h_1, h_2, \dots, h_k$。下面将解释它的含义。
玩家们分配所有卡牌后,应使每个玩家都持有恰好 $k$ 张卡牌并使他们的欢乐值总和最大。在分配完所有卡牌后,每个玩家计算他手中包含他喜欢的数字的卡牌数量。如果玩家持有 $t$ 张包含他喜欢数字的卡牌,则他的欢乐值等于 $h_t$。如果玩家没有得到他喜欢数字的卡牌(即 $t=0$),则他的欢乐值为 $0$。
输出在分配卡牌后玩家的最大可能总欢乐值。请注意,序列 $h_1, \dots, h_k$ 对于所有玩家都是相同的。
输入格式
输入的第一行包含两个整数 $n$ 和 $k$($1 \le n \le 500, 1 \le k \le 10$)——玩家数量和每个玩家将获得的卡牌数量。
第二行包含 $k \cdot n$ 个整数 $c_1, c_2, \dots, c_{k \cdot n}$($1 \le c_i \le 10^5$)——卡牌上的数字。
第三行包含 $n$ 个整数 $f_1, f_2, \dots, f_n$($1 \le f_j \le 10^5$)——玩家喜欢的数字。
第四行包含 $k$ 个整数 $h_1, h_2, \dots, h_k$($1 \le h_t \le 10^5$),其中 $h_t$ 是玩家获得恰好 $t$ 张写有他喜欢数字的卡牌时的欢乐值。保证对于每个 $t \in [2..k]$,条件 $h_{t - 1} < h_t$ 成立。
输出格式
输出一个整数——在所有可能的卡牌分配中,玩家的最大可能总欢乐值。
说明/提示
In the first example, one possible optimal card distribution is the following:
- Player $ 1 $ gets cards with numbers $ [1, 3, 8] $ ;
- Player $ 2 $ gets cards with numbers $ [2, 2, 8] $ ;
- Player $ 3 $ gets cards with numbers $ [2, 2, 8] $ ;
- Player $ 4 $ gets cards with numbers $ [5, 5, 5] $ .
Thus, the answer is $ 2 + 6 + 6 + 7 = 21 $ .
In the second example, no player can get a card with his favorite number. Thus, the answer is $ 0 $ .