CF999F.Cards and Joy

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn players sitting at the card table. Each player has a favorite number. The favorite number of the jj-th player is fjf_j.

There are k⋅nk \cdot n cards on the table. Each card contains a single integer: the ii-th card contains number cic_i. Also, you are given a sequence h1,h2,…,hkh_1, h_2, \dots, h_k. Its meaning will be explained below.

The players have to distribute all the cards in such a way that each of them will hold exactly kk cards. After all the cards are distributed, each player counts the number of cards he has that contains his favorite number. The joy level of a player equals hth_t if the player holds tt cards containing his favorite number. If a player gets no cards with his favorite number (i.e., t=0t=0), his joy level is 00.

Print the maximum possible total joy levels of the players after the cards are distributed. Note that the sequence h1,…,hkh_1, \dots, h_k is the same for all the players.

有 nn 名玩家围坐在一张牌桌旁。每名玩家都有一个最喜爱的数字,第 jj 名玩家最喜爱的数字为 fjf_j。

桌上有 k⋅nk \cdot n 张牌。每张牌上写有一个整数:第 ii 张牌上的数字为 cic_i。此外,你还被给定一个序列 h1,h2,…,hkh_1, h_2, \dots, h_k,其含义将在下文说明。

玩家需将所有牌分发完毕,使得每人恰好持有 kk 张牌。在所有牌分发完毕后,每名玩家统计自己手中写有其最喜爱数字的牌的数量。若某玩家手中恰好有 tt 张写有其最喜爱数字的牌,则该玩家的快乐值为 hth_t;若某玩家手中没有写有其最喜爱数字的牌(即 t=0t = 0),则其快乐值为 00。

请输出在所有可能的分牌方案中,所有玩家快乐值之和的最大可能值。注意,对所有玩家而言,序列 h1,…,hkh_1, \dots, h_k 是完全相同的。

输入格式

The first line of input contains two integers nn and kk (1≤n≤500,1≤k≤101 \le n \le 500, 1 \le k \le 10) — the number of players and the number of cards each player will get.

The second line contains k⋅nk \cdot n integers c1,c2,…,ck⋅nc_1, c_2, \dots, c_{k \cdot n} (1≤ci≤1051 \le c_i \le 10^5) — the numbers written on the cards.

The third line contains nn integers f1,f2,…,fnf_1, f_2, \dots, f_n (1≤fj≤1051 \le f_j \le 10^5) — the favorite numbers of the players.

The fourth line contains kk integers h1,h2,…,hkh_1, h_2, \dots, h_k (1≤ht≤1051 \le h_t \le 10^5), where hth_t is the joy level of a player if he gets exactly tt cards with his favorite number written on them. It is guaranteed that the condition ht−1<hth_{t - 1} \lt h_t holds for each t∈[2..k]t \in [2..k].

输入的第一行包含两个整数 nn 和 kk(1≤n≤5001 \le n \le 500,1≤k≤101 \le k \le 10)—— 分别表示玩家人数以及每位玩家将获得的卡片数量。

第二行包含 k⋅nk \cdot n 个整数 c1,c2,…,ck⋅nc_1, c_2, \dots, c_{k \cdot n}(1≤ci≤1051 \le c_i \le 10^5)—— 表示每张卡片上所写的数字。

第三行包含 nn 个整数 f1,f2,…,fnf_1, f_2, \dots, f_n(1≤fj≤1051 \le f_j \le 10^5)—— 表示各位玩家各自喜欢的数字。

第四行包含 kk 个整数 h1,h2,…,hkh_1, h_2, \dots, h_k(1≤ht≤1051 \le h_t \le 10^5),其中 hth_t 表示某位玩家恰好获得 tt 张写有其喜欢数字的卡片时所获得的快乐值。保证对每个 t∈[2..k]t \in [2..k] 均满足 ht−1<hth_{t - 1} \lt h_t。

输出格式

Print one integer — the maximum possible total joy levels of the players among all possible card distributions.

输出一个整数——在所有可能的卡片分配方案中,玩家总喜悦度的最大值。

输入输出样例

  • 输入#1

    4 3
    1 3 2 8 5 5 8 2 2 8 5 2
    1 2 2 5
    2 6 7

    输出#1

    21
  • 输入#2

    3 3
    9 9 9 9 9 9 9 9 9
    1 2 3
    1 2 3

    输出#2

    0

说明/提示

In the first example, one possible optimal card distribution is the following:

  • Player 11 gets cards with numbers [1,3,8][1, 3, 8];
  • Player 22 gets cards with numbers [2,2,8][2, 2, 8];
  • Player 33 gets cards with numbers [2,2,8][2, 2, 8];
  • Player 44 gets cards with numbers [5,5,5][5, 5, 5].

Thus, the answer is 2+6+6+7=212 + 6 + 6 + 7 = 21.

In the second example, no player can get a card with his favorite number. Thus, the answer is 00.

在第一个例子中,一种可能的最优发牌方案如下:

  • 玩家 11 获得编号为 [1,3,8][1, 3, 8] 的牌;
  • 玩家 22 获得编号为 [2,2,8][2, 2, 8] 的牌;
  • 玩家 33 获得编号为 [2,2,8][2, 2, 8] 的牌;
  • 玩家 44 获得编号为 [5,5,5][5, 5, 5] 的牌。

因此,答案为 2+6+6+7=212 + 6 + 6 + 7 = 21。

在第二个例子中,没有任何玩家能获得其最喜欢数字的牌。因此,答案为 00。

输入解题思路,AI测评打分。不知道怎么写?

首页