CF999F.Cards and Joy
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n players sitting at the card table. Each player has a favorite number. The favorite number of the j -th player is fj .
There are k⋅n cards on the table. Each card contains a single integer: the i -th card contains number ci . Also, you are given a sequence h1,h2,…,hk . 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 k 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 ht if the player holds t cards containing his favorite number. If a player gets no cards with his favorite number (i.e., t=0 ), his joy level is 0 .
Print the maximum possible total joy levels of the players after the cards are distributed. Note that the sequence h1,…,hk is the same for all the players.
输入格式
The first line of input contains two integers n and k ( 1≤n≤500,1≤k≤10 ) — the number of players and the number of cards each player will get.
The second line contains k⋅n integers c1,c2,…,ck⋅n ( 1≤ci≤105 ) — the numbers written on the cards.
The third line contains n integers f1,f2,…,fn ( 1≤fj≤105 ) — the favorite numbers of the players.
The fourth line contains k integers h1,h2,…,hk ( 1≤ht≤105 ), where ht is the joy level of a player if he gets exactly t cards with his favorite number written on them. It is guaranteed that the condition ht−1<ht holds for each t∈[2..k] .
输出格式
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 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 .