(Tree-like array) codeforces Round #413 c-fountains

Source: Internet
Author: User

Arkady plays gardenscapes a lot. Arkady wants to build and new fountains. There is n available fountains, for each fountain it beauty and cost is known. There is, 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 is allowed.

Help Arkady to find, fountains with maximum total beauty so, 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 II 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 are the cost of Fountain i: in coins or in diamonds, re spectively.

Output

Print The maximum total beauty of exactly-fountains Arkady can build. If He can ' t build the fountains, print 0.

Example

Input
3 7 6
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
Ten 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 has 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 is the fountains, but Arkady can ' t build both of them, because he needs 5 coins for the F Irst Fountain, and Arkady have only 4 coins.

1#include <iostream>2#include <string>3#include <algorithm>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <queue>8#include <Set>9#include <map>Ten#include <list> One#include <stack> A #defineMP Make_pair -typedefLong Longll; -typedef unsignedLong Longull; the Const intmax=1e5; - Const intinf=1e9+5; - Const Doublem=4e18; - using namespacestd; + Const intmod=1e9+7; -typedef pair<int,int>PII; + Const Doubleeps=0.000000001; A intc[max+5],d[max+5]; at voidAddint*tree,intKintnum) - { -      while(k<=MAX) -     { -tree[k]=Max (tree[k],num); -k+=k& (-k); in     } - } to intReadint*tree,intk) + { -     intRe=0; the      while(k) *     { $Re=Max (re,tree[k]);Panax Notoginsengk-=k& (-k); -     } the     returnre; + } A intn,c,d,b,p; the intAn,tem; + Charopt[Ten]; - intMain () $ { $scanf"%d%d%d",&n,&c,&d); -      while(n--) -     { thescanf"%d%d%s",&b,&p,opt); -tem=0;Wuyi         if(opt[0]=='C') the         { -             if(p>c) Wu                 Continue; -re+=read (d,d); AboutTem=max (Tem,read (c,c-p)); $ Add (c,p,b); -         } -         Else -         { A             if(p>d) +                 Continue; there+=read (c,c); -Tem=max (Tem,read (d,d-p)); $ Add (d,p,b); the         } the         if(TEM) theAn=max (an,tem+b); the     } -printf"%d\n", an); in     return 0; the}
View Code

The first time to write bit, feel more than the line number of lines tree code is indeed much less, but now more complex operation is not written with bit ...

(Tree-like array) codeforces Round #413 c-fountains

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.