您的位置:首页 > 大数据 > 人工智能

Codeforces Round #413 C. Fountains

2017-05-14 22:09 281 查看
传送门

C. Fountains

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

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 n, c 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<
4000/div>
3 10 105 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 5coins for the first fountain, and Arkady
has only 4 coins.

大意:修两个喷泉。有两种货币。一种是硬币。一种是钻石(- -  好像是把。。)

硬币用C 表示 钻石用D表示。 n c d n是下面有n种喷泉。 c是这个人有的硬币总数 d是钻石总数。

下面n行 每一行代表 这个喷泉的魅力值b 话费的钱 p 钱的哪种类型。

问魅力值的最大是多少。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;

const int maxn = 100000;

int C[maxn+10],D[maxn+10];

void add(int *tree,int k,int num)
{
while(k<=maxn)
{
tree[k] = max(tree[k],num); //更新这个点的最大值
k+=k&-k;
}
}

int read(int *tree,int k)
{
int res=0;
while(k)
{
res = max(res,tree[k]); // 求这一段的的最大值
k-=k&-k;
}
return res;
}

int main(void)
{
int n,c,d,i,j;
while(scanf("%d%d%d",&n,&c,&d)==3)
{
memset(C,0,sizeof(C));
memset(D,0,sizeof(D));
int ans = 0;
for(i=1;i<=n;i++)
{
int b,p;
char t[5];
scanf("%d%d%s",&b,&p,t);
int maxn;
if(t[0] == 'C')
{
maxn = read(D,d);
if(p > c)
continue;
maxn = max(maxn,read(C,c-p));
add(C,p,b);
}
else
{
maxn = read(C,c);
if(p > d)
continue;
maxn = max(maxn,read(D,d-p));
add(D,p,b);
}
if(maxn)
ans = max(ans,maxn + b);
}
cout << ans << endl;
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: