CF321B.Ciel and Duel

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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.

小狐 Ciel 正在与她的朋友 Jiro 玩一款卡牌游戏。

Jiro 拥有 nn 张卡牌,每张卡牌有两个属性:位置(攻击型或防御型)和力量值。Ciel 拥有 mm 张卡牌,每张卡牌也具有这两个属性;已知 Ciel 的所有卡牌的位置均为攻击型。

现在处于 Ciel 的战斗阶段,她可以执行以下操作若干次:

  1. 选择一张她尚未使用过的卡牌 XX;
  2. 若此时 Jiro 没有存活的卡牌,则 Jiro 受到等同于 XX 的力量值的伤害;否则,Ciel 必须选择一张 Jiro 当前存活的卡牌 YY,然后:
    • 若 YY 的位置为攻击型,则必须满足 XX 的力量值 ≥Y\geq Y 的力量值;此次攻击后,卡牌 YY 死亡,Jiro 受到的伤害为 XX 的力量值减去 YY 的力量值(即 X’s strength−Y’s strengthX\text{'s strength} - Y\text{'s strength});
    • 若 YY 的位置为防御型,则必须满足 XX 的力量值 >Y> Y 的力量值;此次攻击后,卡牌 YY 死亡,但 Jiro 不受到任何伤害。

Ciel 可以在任意时刻结束其战斗阶段(即她不必使用全部卡牌)。请帮助小狐计算 Jiro 可能受到的最大总伤害值。

输入格式

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.

第一行包含两个整数 nn 和 mm(1≤n,m≤1001 \leq n, m \leq 100)——分别表示 Jiro 和 Ciel 手中卡牌的数量。

接下来的 nn 行中,每行包含一个字符串 positionposition 和一个整数 strengthstrength(0≤strength≤80000 \leq strength \leq 8000)——分别表示 Jiro 当前卡牌的位置和攻击力。其中位置为字符串 "ATK" 表示攻击型,字符串 "DEF" 表示防御型。

再接下来的 mm 行中,每行包含一个整数 strengthstrength(0≤strength≤80000 \leq strength \leq 8000)——表示 Ciel 当前卡牌的攻击力。

输出格式

Output an integer: the maximal damage Jiro can get.

输出一个整数:Jiro 可能受到的最大伤害。

输入输出样例

  • 输入#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.

在第一个测试用例中,Ciel 拥有 3 张具有相同攻击力的卡片。最优策略如下:首先,她使用其中一张卡片攻击“ATK 2000”卡片,此次攻击摧毁该卡片,Jiro 受到 2500−2000=5002500 - 2000 = 500 点伤害;接着,她使用第二张卡片摧毁“DEF 1700”卡片,此时 Jiro 不受伤害;此时 Jiro 已无任何卡片,因此她可使用第三张卡片直接攻击 Jiro,Jiro 受到 2500 点伤害。故总伤害为 500+2500=3000500 + 2500 = 3000。

在第二个测试用例中,她应使用“1001”卡片攻击“ATK 100”卡片,再使用“101”卡片攻击“ATK 10”卡片。此时 Ciel 仍有剩余卡片,但她可选择结束战斗阶段。总伤害为 (1001−100)+(101−10)=992(1001 - 100) + (101 - 10) = 992。

在第三个测试用例中,请注意:她可以使用攻击力为 0 的卡片摧毁“ATK 0”卡片,但无法用该卡片摧毁“DEF 0”卡片。

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

首页