Ciel and Duel

题意翻译

### 题目描述 $Ciel$ 某天兴致勃勃地找 $Juro$ 玩起了一种卡牌游戏。每张卡牌有类型(攻击或防御)和力量值两个信息。 $Juro$ 有 $n$ 张卡牌,$Ciel$ 有 $m$ 张卡牌。已知 $Ciel$ 的卡牌全是攻击型的。 游戏的每一轮都由 $Ciel$ 进行操作,首先从自己手上选择一张没有使用过的卡牌X。 如果 $Juro$ 手上没有卡牌,受到的伤害为 X 的力量值,否则 $Ciel$ 要从 $Juro$ 的手上选择一张卡牌 Y 。 若 Y 是攻击型(当 X 的力量值不小于 Y 的力量值时才可选择),此轮结束后 Y 消失,$Juro$ 受到的伤害为 X 的力量值与 Y 的力量值的差;若 Y 是防御型(当 X 的力量值大于 Y 的力量值时才可选择),此轮结束后 Y 消失,$Juro$ 不受到伤害。 $Ciel$ 可以随时结束自己的操作(卡牌不一定要用完)。她想使得 $Juro$ 受到的总伤害最大。你知道自己要做什么了吗? ### Input 输入的第一行包含两个整数 $n$ 和 $m$ 。 接下来 $n$ 行每行包含一个字符串和一个整数,分别表示 $Juro$ 的一张卡牌的类型(“ATK”表示攻击型,“DEF”表示防御型)和力量值。 接下来 $m$ 行每行包含一个整数,表示 $Ciel$ 的一张卡牌的力量值。 ### Output 输出一行包含一个整数,表示$Juro$ 受到的最大总伤害。

题目描述

Fox Ciel is playing a card game with her friend Jiro. Jiro has $ n $ cards, each one has two attributes: $ position $ (Attack or Defense) and $ strength $ . Fox Ciel has $ m $ cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the following operation many times: 1. Choose one of her cards $ X $ . This card mustn't be chosen before. 2. If Jiro has no alive cards at that moment, he gets the damage equal to ( $ X $ 's strength). Otherwise, Ciel needs to choose one Jiro's alive card $ Y $ , then: - If $ Y $ 's position is Attack, then ( $ X $ 's strength) $ >= $ ( $ Y $ 's strength) must hold. After this attack, card $ Y $ dies, and Jiro gets the damage equal to ( $ X $ 's strength) - ( $ Y $ 's strength). - If $ Y $ 's position is Defense, then ( $ X $ 's strength) $ > $ ( $ Y $ 's strength) must hold. After this attack, card $ Y $ dies, but Jiro gets no damage. Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get.

输入输出格式

输入格式


The first line contains two integers $ n $ and $ m $ ( $ 1<=n,m<=100 $ ) — the number of cards Jiro and Ciel have. Each of the next $ n $ lines contains a string $ position $ and an integer $ strength $ $ (0<=strength<=8000) $ — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense. Each of the next $ m $ lines contains an integer $ strength $ ( $ 0<=strength<=8000 $ ) — the strength of Ciel's current card.

输出格式


Output an integer: the maximal damage Jiro can get.

输入输出样例

输入样例 #1

2 3
ATK 2000
DEF 1700
2500
2500
2500

输出样例 #1

3000

输入样例 #2

3 4
ATK 10
ATK 100
ATK 1000
1
11
101
1001

输出样例 #2

992

输入样例 #3

2 4
DEF 0
ATK 0
0
0
1
1

输出样例 #3

1

说明

In the first test case, Ciel has 3 cards with same $ strength $ . The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets $ 2500-2000=500 $ damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets $ 2500 $ damage. So the answer is $ 500+2500=3000 $ . In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals $ (1001-100)+(101-10)=992 $ . In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card.