Playrix codescapes Cup (codeforces Round #413, rated, Div. 1 + div. 2) C. Fountains "tree-like array maintenance interval Maximum"

Source: Internet
Author: User

Topic Portal: Http://codeforces.com/contest/799/problem/C

C. Fountains Time limit per test 2 seconds memory limit per test Megabytes input Standard Input Output Standard Output

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.

Examplesinput
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.

Main topic:

There are N pools, each with ornamental values and costs (gold or diamonds); Arkady has a C gold coin D Diamond, he wants to build two pools, making the highest ornamental value.

Problem Solving Ideas:

The tree array maintains the maximum amount of gold and diamonds that can be spent, and each time the input compares three possibilities of one gold coin for one diamond, two gold, and two diamonds.

AC Code:

1#include <bits/stdc++.h>2 #defineINF 0x3f3f3f3f3 #definell Long Long int4 using namespacestd;5 6 Const intMAXN = 1e5+Ten;7 8 intT_1[MAXN], T_2[MAXN];9 intN, Num_c, num_d;Ten  One intLowbit (intx) A { -     returnx& (-x); - } the voidAddintNointStintvalue) - { -      for(inti = st; I <= MAXN; i+=lowbit (i)) -     { +         if(no) t_1[i] =Max (T_1[i], value); -         ElseT_2[i] =Max (T_2[i], value); +     } A } at  - intQueryintNointSt) - { -     intres =0; -      for(inti = st; i >0; i-=lowbit (i)) -     { in         if(NO) res =Max (res, t_1[i]); -         Elseres =Max (res, t_2[i]); to     } +     returnRes; - } the intMain () * { $     Charstr[3];Panax Notoginseng     intAns_max =0, A, b, ans =0; -scanf"%d%d%d", &n, &num_c, &num_d); the      for(inti =1; I <= N; i++) +     { Ascanf"%d%d", &a, &b); thescanf"%s", str); +         if(str[0] =='C'){ -Ans_max = Query (0, num_d); $             if(b > Num_c)Continue; $Ans_max = max (Ans_max, query (1, num_c-b)); -Add1, B, a); -         } the         Else{ -Ans_max = Query (1, num_c);Wuyi             if(b > Num_d)Continue; theAns_max = max (Ans_max, query (0, num_d-b)); -Add0, B, a); Wu         } -         if(ans_max) ans = max (ans, ans_max+a); About     } $printf"%d\n", ans); -     return 0; -}
View Code

Playrix codescapes Cup (codeforces Round #413, rated, Div. 1 + div. 2) C. Fountains "tree-like array maintenance interval Maximum"

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.