一道贪心题。

可以分两种情况

1 、是没有把对面的牌全打败,那么只要用最大的可能去打攻击状态的牌。

2、 是将对面的牌全打败,那么只要保证打对面防守状态的花费最小,就可以保证最后的结果最大

两种情况下的最大值就我们要的答案.

D. Ciel and Duel
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 test(s)
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
Note

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 gets2500 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.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <sstream>
#include <iostream>
using namespace std;
#define INF 0x3fffffff // 抗住! 一切都会好的! struct node
{
int key,id;
}g[]; int k[];
int def[],atk[]; int cmp(int t,int t1)
{
return t>t1;
} int main()
{
//freopen("//home//chen//Desktop//ACM//in.text","r",stdin);
//freopen("//home//chen//Desktop//ACM//out.text","w",stdout);
int n,m;
scanf("%d%d",&n,&m);
int cntd=,cnta=;
int sumd=,suma=;
for(int i=;i<n;i++)
{
string str;
int tmp;
cin>>str>>tmp;
if(str=="ATK")
{
suma+=tmp;
atk[cnta++]=tmp;
g[i].key=tmp;
g[i].id=;
}
else
{
sumd+=tmp;
def[cntd++]=tmp;
g[i].key=tmp;
g[i].id=;
}
}
int sum=;
for(int i=;i<m;i++)
{
cin>>k[i];
sum+=k[i];
}
int mx=-;
//求全攻击时的最大伤害
int tmp=;
sort(atk,atk+cnta);
sort(k,k+m,cmp);
int tend=min(m,cnta);
for(int i=;i<tend;i++)
{
if(k[i]>=atk[i])
{
tmp += k[i]-atk[i];
}
else break;
}
mx = max(mx,tmp); //////////////// 先判断 能不能把对面的全部清除掉
int flag[];
memset(flag,,sizeof(flag));
sort(k,k+m);
int sign=;
for(int i=;i<n;i++)
{
int flag1=;
for(int j=;j<m;j++)
{
if(flag[j]==) continue;
if(g[i].id==)
{
if(k[j]>=g[i].key)
{
flag1=;
flag[j]=;
break;
}
}
else
{
if(k[j]>g[i].key)
{
flag1=;
flag[j]=;
break;
}
}
}
if(flag1==)
{
sign=;
break;
}
}
if(sign==)
{
printf("%d\n",mx);
return ;
}
//////////////// 求将对面全清时的最大值
tmp = ;
memset(flag,,sizeof(flag));
sort(def,def+cntd);
for(int i=;i<cntd;i++)
{
for(int j=;j<m;j++)
{
if(flag[j]==) continue;
if(k[j] > def[i])
{
flag[j]=;
tmp+=k[j];
break;
}
}
}
printf("%d\n",max(sum-tmp-suma,mx)); // 大概就是这个意思
return ;
}

Codeforces Round #190 (Div. 2).D的更多相关文章

  1. Codeforces Round #190 (Div. 2) B. Ciel and Flowers

    链接:http://codeforces.com/contest/322/problem/B 这题做错了.没考虑周全. #include <cstdio> #include <cst ...

  2. Codeforces Round #190 (Div. 2) E. Ciel the Commander 点分治

    E. Ciel the Commander Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest ...

  3. 树上的构造 树分治+树重心的性质 Codeforces Round #190 (Div. 2) E

    http://codeforces.com/contest/322/problem/E E. Ciel the Commander time limit per test 1 second memor ...

  4. Codeforces Round #190 DIV.2 A. Ciel and Dancing

    #include <cstdio> #include <iostream> #include <vector> using namespace std; int m ...

  5. Codeforces Round 190 div.2 322C 321A Ciel and Robot

    唔...这题是数学题. 比赛时做出来,但题意理解错了,以为只要判断那点是不是在线上就行了,发现过不了样例就没提交. 思路:记录每一步的偏移,假设那点是在路径上的某步,然后回推出那一个周期的第一步,判断 ...

  6. Codeforces Round #190 (Div. 2) 水果俩水题

    后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...

  7. [置顶] Codeforces Round #190 (Div. 2)(完全)

    好久没有写博客了,一直找不到有意义的题可以写,这次也不算多么有意义,只是今天是比较空的一天,趁这个时候写一写. A. B. 有一点贪心,先把每个拿去3的倍数,余下0或1或2,然后三个一起拿. 对于以上 ...

  8. Codeforces Round #190 (Div. 1 + Div. 2)

    A. Ciel and Dancing 模拟. B. Ciel and Flowers 混合类型的数量只能为0.1.2,否则3个可以分成各种类型各自合成. C. Ciel and Robot 考虑一组 ...

  9. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. JS和JSP的差别

    近期非常多同学在纠结于名词缩写之间的相似性.因此本人也来写一篇,讲讲JS和JSP的差别. SUN首先发展出SERVLET,其功能比較强劲,体系设计也非常先进,仅仅是,它输出HTML语句还是採用了老的C ...

  2. MockServer 入门

    忽略元数据末回到原数据开始处 MockServer介绍及文档 借鉴公司的文档 http://mock-server.com github:https://github.com/jamesdbloom/ ...

  3. windows 2003 群集

    http://www.tudou.com/programs/view/-UZoSIuUvXs/

  4. 【iOS开发之Objective-C】书签管理器项目

    1.项目 新建一个书签管理器的项目,能够存储书签的网址.中文名.星级.訪问量和权限信息.具有增.删.改.查和排序的功能. 2.找对象,抽象类 书签管理器,书签管理器.书签管理器--  多读几次书是不是 ...

  5. atitit.orm的缺点与orm框架市场占有率,选型attilax总结

    atitit.orm的缺点与orm框架市场占有率,选型attilax总结 1. attilax的orm框架要求 1 2. orm框架市场占有率 2 3. spring jdbc templt 3 4. ...

  6. JSON 之GSON 解析

    一. 谷歌GSON这个Java类库可以把Java对象转换成JSON,也可以把JSON字符串转换成一个相等的Java对象.Gson支持任意复杂Java对象包括没有源代码的对象. 二.Gson解析Json ...

  7. django 文件上传(阿里云oss)下载(支持大文件下载)

    1.文件上传 Models 设计 class Upload_File(models.Model): image = models.FileField(upload_to='file/%Y/%m',de ...

  8. jdom 插入 修改 删除

    创建XML文档 XML文件是一种典型的树形文件,每个文档元素都是一个document元素的子节点.而每个子元素都是一个Element对象,对象可以向下包含. 1 因此我们可以通过先创建元素再将元素添加 ...

  9. python操作word(改课文格式)【最终版】

    python操作word的一些方法,前面写了一些感悟,有点跑题,改了下题目,方便能搜索到.心急的可以直接拉到最后看代码,我都加了比较详细的注释. 从8.3号早上9点,到8.8号下午5点半下班,终于把这 ...

  10. hadoop之mapreduce编程实例(系统日志初步清洗过滤处理)

    刚刚开始接触hadoop的时候,总觉得必须要先安装hadoop集群才能开始学习MR编程,其实并不用这样,当然如果你有条件有机器那最好是自己安装配置一个hadoop集群,这样你会更容易理解其工作原理.我 ...