Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.

Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.

Input

The first line contains three integers nc and d (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100 000) — the number of fountains, the number of coins and diamonds Arkady has.

The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 ≤ bi, pi ≤ 100 000) — the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.

Output

Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.

Examples

Input

3 7 6
10 8 C
4 3 C
5 6 D

Output

9

Input

2 4 5
2 5 C
2 1 D

Output

0

Input

3 10 10
5 5 C
5 5 C
10 11 D

Output

10

Note

In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.

In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins.

思路:见代码

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#define MAX 100005 using namespace std;
typedef long long ll; int n,c,d,b,cost,cnt,maxs;
char type; struct node{
int b,cost;
char type;
};
node f[MAX]; bool cmp(node x,node y) {
if(x.b!=y.b)
return x.b>y.b;
else
{
return x.cost<y.cost;
}
}//排序按照美丽值排序,如果相等就按照花费小排 int main() {
while(scanf("%d%d%d",&n,&c,&d)!=EOF) {
maxs=0;
for(int i=0; i<n; i++) {
scanf("%d%d %c",&b,&cost,&type);
f[i].b=b;
f[i].cost=cost;
f[i].type=type;
}//输入
sort(f,f+n,cmp);
int max1=0,max2=0;
for(int i=0; i<n; i++) {
if(f[i].type=='C'&&f[i].cost<=c) {
max1=f[i].b;
break;
} }
for(int i=0; i<n; i++) {
if(f[i].type=='D'&&f[i].cost<=d) {
max2=f[i].b;
break;
}
}//第一种情况,在用硬币的和用钻石的分别一个
int maxxn=0;
//这种情况必须保证都能得到,如果有一个不够就直接是原来的0就行了,表示这种情况不成立
if(max1!=0&&max2!=0) {
maxxn=max1+max2;
}
//第二种情况,都从用硬币的取两个或者都从用钻石的取两个,这样枚举的时候是有技巧的,不然n^2必然超时
//也要庆幸数据没有都卡到最后
for(int i=0; i<n; i++) {
int t1=c;
int t2=d;
if(f[i].type=='C'&&t1<=f[i].cost)
continue;
else if(f[i].type=='D'&&t2<=f[i].cost)
continue;
if(f[i].type=='C'&&t1>f[i].cost) {
t1-=f[i].cost;
cnt=0;
cnt+=f[i].b;
} else if(f[i].type=='D'&&t2>f[i].cost) {
t2-=f[i].cost;
cnt=0;
cnt+=f[i].b;
}
for(int j=i+1; j<n; j++) {
if(f[j].type=='C'&&f[j].cost<=t1) {
cnt+=f[j].b;
maxs=max(maxs,cnt);
break;
} else if(f[j].type=='D'&&f[j].cost<=t2) {
cnt+=f[j].b;
maxs=max(maxs,cnt);
break;
}
}
} printf("%d\n",max(maxs,maxxn)); }
return 0;
}

Fountains(非线段树版(主要是不太会用))的更多相关文章

  1. Matrix(线段树版)

    poj2155:http://poj.org/problem?id=2155 题意;同上一遍随笔. 题解:这里用二维线段树打了一发.第一次学习别人的代码.才学的.这种树套树的程序,确实很费脑子,一不小 ...

  2. BZOJ2028:[SHOI2009]会场预约(线段树版)

    浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:https://www.lydsy.com/JudgeOnline/prob ...

  3. Color the ball HDU - 1556 (非线段树做法)

    题意:在1到n的气球中,在不同的区域中涂颜色,问每个气球涂几次. #include<cstdio>int num[100010];int main(){ int n, x, y;; whi ...

  4. hdu 1556 Color the ball(非线段树做法)

    #include<stdio.h> #include<string.h> ]; int main() { int n,i; int a,b; while(scanf(" ...

  5. ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】

     FZU 2105  Digits Count Time Limit:10000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  6. zkw线段树详解

    转载自:http://blog.csdn.net/qq_18455665/article/details/50989113 前言 首先说说出处: 清华大学 张昆玮(zkw) - ppt <统计的 ...

  7. Luogu P3740 [HAOI2014]贴海报_线段树

    线段树版的海报 实际上这个与普通的线段树相差不大,只是貌似数据太水,暴力都可以过啊 本来以为要离散的,结果没打就A了 #include<iostream> #include<cstd ...

  8. 洛谷.3733.[HAOI2017]八纵八横(线性基 线段树分治 bitset)

    LOJ 洛谷 最基本的思路同BZOJ2115 Xor,将图中所有环的异或和插入线性基,求一下线性基中数的异或最大值. 用bitset优化一下,暴力的复杂度是\(O(\frac{qmL^2}{w})\) ...

  9. Gym 101911E "Painting the Fence"(线段树区间更新+双端队列)

    传送门 题意: 庭院中有 n 个围栏,每个围栏上都被涂上了不同的颜色(数字表示): 有 m 条指令,每条指令给出一个整数 x ,你要做的就是将区间[ x第一次出现的位置 , x最后出现的位置 ]中的围 ...

随机推荐

  1. Mybatis简化sql书写,别名的使用

    之前,我们在sql映射xml文件中的引用实体类时,需要写上实体类的全类名(包名+类名),如下: <!-- 创建用户(Create) --> <insert id="addU ...

  2. c语言实践 统计输入的一串正整数里面奇数和偶数的个数

    怎么考虑这个问题. 首先先确定肯定是需要一个变量保存输入的数据的,我们叫它input,最后结果要的是个数,所以需要另外两个变量来保存奇数的个数和偶数的个数. int input int countJ ...

  3. 符合mvc思维的分页思想

    .Model Student.cs namespace WebApplication14.Models { public class Student { public int Id { get; se ...

  4. SpringMVC——文件的上传

    一.加入依赖 commons-io-2.0.jar commons-fileupload-1.2.1.jar 二.接口MultipartResolver Spring MVC 为文件上传提供了直接的支 ...

  5. 编写高质量代码改善C#程序的157个建议——建议42:使用泛型参数兼容泛型接口的不可变性

    建议42:使用泛型参数兼容泛型接口的不可变性 让返回值类型返回比声明的类型派生程度更大的类型,就是“协变”.如: public Employee GetAEmployee(string name) { ...

  6. windows phone之依赖属性(DependencyProperty)

    Windows Presentation Foundation (WPF) 提供了一组服务,这些服务可用于扩展公共语言运行时 (CLR) 属性的功能,这些服务通常统称为 WPF 属性系统.由 WPF ...

  7. C# 微信openid 用户信息

    前段demo index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...

  8. conda install 安装太慢怎么办?

    小编我在安装tensorflow和keras的过程中,安装进程太慢,小木棍一直在转圈...抓狂... 如何解决??? 使用清华提供的anaconda镜像,使用以后真的很快! Anaconda 镜像使用 ...

  9. 趣图:向客户介绍的产品VS实际开发的产品

      趣图:客户需求 vs 最终产品 趣图:你永远想不到用户怎么使用你的产品

  10. Java程序员修炼之路

    作者简介:王成委,CSDN知识库特邀编辑,Java高级工程师,熟悉Java编程语言和Oracle数据库.专注于高并发架构设计和大数据存储方向的研究. 我们为什么选择Java 大多数人选择Java可能只 ...