Playrix Codescapes Cup (Codeforces Round 413, rated, Div. 1 + Div. 2)
C
Fountains
Codeforces
1800
原题
← BD →
翻译中…

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 $*b*_{*i*}$ and $*p*_{*i*}$ ($1 ≤ *b*_{*i*}, *p*_{*i*} ≤ 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.

翻译中…

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.

翻译中…

样例

Input #1
3 7 6
10 8 C
4 3 C
5 6 D
Output #1
9
InputCopy OutputCopy
Input #2
2 4 5
2 5 C
2 1 D
Output #2
0
InputCopy OutputCopy
Input #3
3 10 10
5 5 C
5 5 C
10 11 D
Output #3
10
InputCopy OutputCopy
题目信息
题号
799C
时间限制
2 s
内存限制
256 MB
标签
二分
数据结构
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。