Codeforces Round #413 C. Fountains

传送门

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 nc and d (2 ≤ n ≤ 100 0000 ≤ 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 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;  
}  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值