zoukankan      html  css  js  c++  java
  • M

    M - Ciel and Duel
    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
    Submit Status
    Appoint description: 

    Description

    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.

    Input

    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

    Output an integer: the maximal damage Jiro can get.

    Sample Input

    Input
    2 3
    ATK 2000
    DEF 1700
    2500
    2500
    2500
    Output
    3000
    Input
    3 4
    ATK 10
    ATK 100
    ATK 1000
    1
    11
    101
    1001
    Output
    992
    Input
    2 4
    DEF 0
    ATK 0
    0
    0
    1
    1
    Output
    1

    FAQ | About Virtual Judge | Forum | Discuss
  • 相关阅读:
    Docker从入门到精通(四)——常用命令
    Docker从入门到精通(二)——安装Docker
    Docker从入门到精通(一)——初识
    Java设计模式之(十三)——模板方法模式
    Java设计模式之(十四)——策略模式
    Docker从入门到精通(七)——容器数据共享
    YCFramework版本更新:V1.0.2
    YCFramework版本更新:V1.0.3
    我的分布式微服务框架:YCFramework
    mysql 多表多字段报表填充查询
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3433654.html
Copyright © 2011-2022 走看看