树状数组维护区间最大值
来源:互联网 发布:mac os x10.10.5 编辑:程序博客网 时间:2024/05/16 17:31
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.
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 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.
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
3 7 610 8 C4 3 C5 6 D
9
2 4 52 5 C2 1 D
0
3 10 105 5 C5 5 C10 11 D
10
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.
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int maxn = 100000; int C[maxn+10],D[maxn+10]; void add(int *tree,int k,int num) { while(k<=maxn) { tree[k] = max(tree[k],num); k+=k&-k; } } int read(int *tree,int k) { int res=0; while(k) { res = max(res,tree[k]); k-=k&-k; } return res; } int main(void) { int n,c,d,i,j; while(scanf("%d%d%d",&n,&c,&d)==3) //n喷泉的数量 c金币数量 d钻石数量 { memset(C,0,sizeof(C)); memset(D,0,sizeof(D)); int ans = 0; for(i=1;i<=n;i++) { int b,p; char t[5]; scanf("%d%d%s",&b,&p,t); //b美丽值 p花费数量 t代表金币或钻石 int maxn; if(t[0] == 'C') { maxn = read(D,d); if(p > c) continue; maxn = max(maxn,read(C,c-p)); add(C,p,b); } else { maxn = read(C,c); if(p > d) continue; maxn = max(maxn,read(D,d-p)); add(D,p,b); } if(maxn) ans = max(ans,maxn + b); } cout << ans << endl; } return 0; }
- 树状数组维护区间最大值
- 树状数组写区间最大值
- 树状数组求区间最大值
- 树状数组求区间最大值
- 51Nod1463 找朋友(离线处理+树状数组维护区间最大值)
- 树状数组求区间最大值一类问题
- poj3264 树状数组维护区间最值
- 树状数组区间维护及单点查询
- 树状数组求区间最大值(树状数组)(复习)
- poj3468 树状数组解法(树状数组维护区间更新)
- codeforces 777E. Hanoi Factory (LIS+dp+树状数组/线段树维护区间最大值及单点更新)
- HDU 1754 I Hate it (树状数组)(区间最大值)
- I Hate It(树状数组--区间求最大值)
- I Hate It 树状数组 单点更新 区间最大值
- 区间信息的维护和查询系列算法-树状数组
- HDU 5480 Conturbatio(二维树状数组维护区间和)
- hdoj 5497 Inversion 【树状数组维护 区间逆序对】
- hdu3966Aragorn's Story(树链剖分+树状数组维护区间)
- 关闭selinux
- Ember旅程系列(五) -- 安装插件
- sheepdog集群节点加入时,视图变化过程分析
- C 的字符串处理函数 strcpy() 与 c++的copy() 函数的不同之处
- 摄氏温度转华氏温度
- 树状数组维护区间最大值
- iptables
- python使用socket实现多线程端口扫描
- LeetCode 37. Sudoku Solver
- http协议:http协议理解
- CSDN博客添加自定义栏目
- samba安装配置《一》
- cocos2dx定时器详解
- 51nod 1184 第N个质数(二分+大区间求素数模板)