Codeforces Round #413 Div. 2 C. Fountains
来源:互联网 发布:c#课本编程题及答案 编辑:程序博客网 时间:2024/04/30 14:21
C. Fountains
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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 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.
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个商品,你有c货币和d货币。给出每个商品的贡献和代价以及能用哪种货币购买。问你能买到两件商品贡献和最大为多少。
题解:枚举一个商品的同时,找到剩余钱所能购买的最大贡献是多少,维护最大值。
代码:
#include<bits/stdc++.h>using namespace std;const int N=1e6;int C[N<<2],D[N<<2];int n,c,d,b,p;string s;void pushup(int rt,int *t){ t[rt]=max(t[rt<<1],t[rt<<1|1]);}void update(int l,int r,int pos,int val,int rt,int *t){ if(l==r) { t[rt]=max(t[rt],val); return ; } int mid=(l+r)>>1; if(pos<=mid) update(l,mid,pos,val,rt<<1,t); else update(mid+1,r,pos,val,rt<<1|1,t); pushup(rt,t);}int query(int l,int r,int ll,int rr,int rt,int *t){ if(ll>rr) return 0; if(ll<=l&&rr>=r) return t[rt]; int res=0; int mid=(r+l)>>1; if(ll<=mid) res=max(res,query(l,mid,ll,rr,rt<<1,t)); if(rr>mid) res=max(res,query(mid+1,r,ll,rr,rt<<1|1,t)); return res;}int main(){ cin>>n>>c>>d; int ans=0; for(int i=1;i<=n;i++) { cin>>b>>p>>s; int sum; if(s=="C") { sum=query(1,N,1,d,1,D); if(p>c) continue; sum=max(sum,query(1,N,1,c-p,1,C)); update(1,N,p,b,1,C); } else { sum=query(1,N,1,c,1,C); if(p>d) continue; sum=max(sum,query(1,N,1,d-p,1,D)); update(1,N,p,b,1,D); } if(sum) ans=max(ans,sum+b); } cout<<ans<<endl;}
- Codeforces Round #413 Div. 2 C. Fountains
- Codeforces Round #413 Div. 1 + Div. 2 C. Fountains
- codeforces Round #413 Div. 1 + Div. 2 C Fountains
- CodeforcesPlayrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)C题C. Fountains
- Codeforces Round #413:C. Fountains
- Codeforces Round #413 C. Fountains
- codeforces round #413 C. Fountains
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains(树状数组)
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C Fountains 乱搞
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C Fountains
- Codeforces Round #413 C. Fountains 二分
- Codeforces Round #413 C-Fountains 树状数组
- Codeforces Round #413 C. Fountains(RMQ线段树)
- Codeforces Round #413 C. Fountains(优先队列乱搞/树状数组/线段树)
- Codeforces 799C. Fountains
- codeforces 799C Fountains
- CF Round #413( Div.1/2) Fountains(线状数组查找)
- 【codeforces】Codeforces Round #370 (Div. 2) C
- 数据链路层:循环冗余检验CRC
- for公司、创业公司
- [bigdata-070] 关于mycat
- test1
- 实训项目第一周2
- Codeforces Round #413 Div. 2 C. Fountains
- 环境搭建
- 利用Python进行数据分析(7) pandas基础: Series和DataFrame的简单介绍
- 程序员面试金典--面试31之像素设定
- [bigdata-071] 《高性能mysql》读书笔记(不全未整理)
- 蓝桥杯 算法提高 队列操作 【stl 基础】
- 基于apache ambari 的大数据平台搭建并运行WordCount
- java web 项目管理
- redis配置文件详解