题目传送门:http://codeforces.com/contest/799/problem/C

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 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 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 5 coins for the first fountain, and Arkady has only 4 coins.

题目大意:

有 N 个水池,每个水池有 观赏值 和 花费(金币或者钻石);Arkady有 C 个金币 D 个钻石,他想建两个水池,使得观赏值最高。

解题思路:

树状数组维护金币和钻石花费范围内所能得到的最大值,每次输入都比较三种可能性一个金币的一个钻石的,两个金币的,两个钻石的。

AC code:

 #include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define ll long long int
using namespace std; const int MAXN = 1e5+; int t_1[MAXN], t_2[MAXN];
int N, num_c, num_d; int lowbit(int x)
{
return x&(-x);
}
void add(int no, int st, int value)
{
for(int i = st; i <= MAXN; i+=lowbit(i))
{
if(no) t_1[i] = max(t_1[i], value);
else t_2[i] = max(t_2[i], value);
}
} int query(int no, int st)
{
int res = ;
for(int i = st; i > ; i-=lowbit(i))
{
if(no) res = max(res, t_1[i]);
else res = max(res, t_2[i]);
}
return res;
}
int main()
{
char str[];
int ans_max = , a, b, ans = ;
scanf("%d%d%d", &N, &num_c, &num_d);
for(int i = ; i <= N; i++)
{
scanf("%d%d", &a, &b);
scanf("%s", str);
if(str[] == 'C'){
ans_max = query(, num_d);
if(b > num_c) continue;
ans_max = max(ans_max, query(, num_c-b));
add(, b, a);
}
else{
ans_max = query(, num_c);
if(b > num_d) continue;
ans_max = max(ans_max, query(, num_d-b));
add(, b, a);
}
if(ans_max) ans = max(ans, ans_max+a);
}
printf("%d\n", ans);
return ;
}

Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains 【树状数组维护区间最大值】的更多相关文章

  1. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)(A.暴力,B.优先队列,C.dp乱搞)

    A. Carrot Cakes time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...

  2. C.Fountains(Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)+线段树+RMQ)

    题目链接:http://codeforces.com/contest/799/problem/C 题目: 题意: 给你n种喷泉的价格和漂亮值,这n种喷泉题目指定用钻石或现金支付(分别用D和C表示),C ...

  3. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) 一夜回到小学生

    我从来没想过自己可以被支配的这么惨,大神讲这个场不容易掉分的啊 A. Carrot Cakes time limit per test 1 second memory limit per test 2 ...

  4. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) E - Aquarium decoration 贪心 + 平衡树

    E - Aquarium decoration 枚举两个人都喜欢的个数,就能得到单个喜欢的个数,然后用平衡树维护前k大的和. #include<bits/stdc++.h> #define ...

  5. 【动态规划】【滚动数组】【搜索】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion

    显然将扩张按从大到小排序之后,只有不超过前34个有效. d[i][j]表示使用前i个扩张,当length为j时,所能得到的最大的width是多少. 然后用二重循环更新即可, d[i][j*A[i]]= ...

  6. 【预处理】【分类讨论】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains

    分几种情况讨论: (1)仅用C或D买两个 ①买两个代价相同的(实际不同)(排个序) ②买两个代价不同的(因为买两个代价相同的情况已经考虑过了,所以此时对于同一个代价,只需要保存美丽度最高的喷泉即可)( ...

  7. 树状数组 Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains

    C. Fountains time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  8. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion

    D. Field expansion time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  9. Codeforces Round #425 (Div. 2) D 树链剖分 + 树状数组维护区间

    一看就知道 可以LCA判断做 也可以树链剖分拿头暴力 然而快速读入和线段树维护区间会T70 于是只能LCA? 线段树的常数不小 于是需要另外一种办法来进行区间加减和查询区间和 就是使用树状数组 这个题 ...

随机推荐

  1. Ba Gua Zhen

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5544 学习链接:https://www.cnblogs.com/qscqesze/p/4902518. ...

  2. Oracle 基础系列之1.2 oracle的基本使用

    在1.1的安装过程完成之后,进入第二部分,oracle的基本使用,在使用前,首先测试下,oracle是否安装成功,以及检查oracle的关键服务时候开启 1.首先测试下,oracle是否安装成功 打开 ...

  3. 让C:\Users文件夹放在D盘

    新安装win7 在安装Win7的过程中,要求输入用户名及密码的时候,先不如输入任何信息,按“Shift+F10”呼出DOS窗口,输入以下命令: robocopy "C:\Users" ...

  4. 数据库~大叔通过脚本生成poco实体

    今天在做开发时,需要把表映射成实体,又没有EF这种工具,就从网上下了一个工具,但使用时觉得太重了,所以就自己写了一个,基于mysql的. 功能:输入表名,得到这个表的poco实体 SELECT COL ...

  5. Unity5.x发布IOS项目Xcode8免签证调试发布教程

    https://www.jianshu.com/p/b0fb49fbcc14 最近尝试发布一下IOS项目,发现现在发布已经简单很多了,不需要开发者账户也能简单快捷进行真机调试. 调试: 1.准备工作 ...

  6. nyoj 206——矩形的个数——————【dp或公式】

    矩形的个数 时间限制:1000 ms  |  内存限制:65535 KB 难度:1   描述 在一个3*2的矩形中,可以找到6个1*1的矩形,4个2*1的矩形3个1*2的矩形,2个2*2的矩形,2个3 ...

  7. 从零开始写C# MVC框架之--- 配置log4日志

    在框架中配置日志分2步,一个是在帮助项目Zy.Utilities--Zy.Utility.Core中新建log类,封装写入日志方法,还需要在Zy.Utility.Core添加 log4net 的引用 ...

  8. C# 使用cookie实现登录

    首先,我们需要做的是什么? 我们成功登录之后,跳转到主界面,然后主界面的登录按钮变成头像啥的.下一次打开网页就要判断有没有登录过,有cookie就不需要登录,直接显示头像 1.成功登录后,客户端请求服 ...

  9. jQuery获取table表中的td标签

    首先我来介绍一下我遇到的问题 1.当有一个table表包含了<tr>标签,<td>标签,大致可以认为是这样的: <tr> <td> @scene.ID ...

  10. artDialog组件应用学习(二)

    一.没有操作选项的对话框 预览: html前台引入代码:(之后各种效果对话框引入代码致,调用方法也一样,就不一一写入) <script type="text/javascript&qu ...