CF799C.Fountains

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are nn 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.

输入格式

The first line contains three integers nn , cc and dd ( 2<=n<=1000002<=n<=100000 , 0<=c,d<=1000000<=c,d<=100000 ) — the number of fountains, the number of coins and diamonds Arkady has.

The next nn lines describe fountains. Each of these lines contain two integers bib_{i} and pip_{i} ( 1<=bi,pi<=1000001<=b_{i},p_{i}<=100000 ) — the beauty and the cost of the ii -th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain ii : in coins or in diamonds, respectively.

输出格式

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

输入输出样例

  • 输入#1

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

    输出#1

    9
    
  • 输入#2

    2 4 5
    2 5 C
    2 1 D
    

    输出#2

    0
    
  • 输入#3

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

    输出#3

    10
    

说明/提示

In the first example Arkady should build the second fountain with beauty 44 , which costs 33 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 55 which costs 66 diamonds. Thus the total beauty of built fountains is 99 .

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

首页