Fountains(非线段树版(主要是不太会用))
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.
思路:见代码
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#define MAX 100005
using namespace std;
typedef long long ll;
int n,c,d,b,cost,cnt,maxs;
char type;
struct node{
int b,cost;
char type;
};
node f[MAX];
bool cmp(node x,node y) {
if(x.b!=y.b)
return x.b>y.b;
else
{
return x.cost<y.cost;
}
}//排序按照美丽值排序,如果相等就按照花费小排
int main() {
while(scanf("%d%d%d",&n,&c,&d)!=EOF) {
maxs=0;
for(int i=0; i<n; i++) {
scanf("%d%d %c",&b,&cost,&type);
f[i].b=b;
f[i].cost=cost;
f[i].type=type;
}//输入
sort(f,f+n,cmp);
int max1=0,max2=0;
for(int i=0; i<n; i++) {
if(f[i].type=='C'&&f[i].cost<=c) {
max1=f[i].b;
break;
}
}
for(int i=0; i<n; i++) {
if(f[i].type=='D'&&f[i].cost<=d) {
max2=f[i].b;
break;
}
}//第一种情况,在用硬币的和用钻石的分别一个
int maxxn=0;
//这种情况必须保证都能得到,如果有一个不够就直接是原来的0就行了,表示这种情况不成立
if(max1!=0&&max2!=0) {
maxxn=max1+max2;
}
//第二种情况,都从用硬币的取两个或者都从用钻石的取两个,这样枚举的时候是有技巧的,不然n^2必然超时
//也要庆幸数据没有都卡到最后
for(int i=0; i<n; i++) {
int t1=c;
int t2=d;
if(f[i].type=='C'&&t1<=f[i].cost)
continue;
else if(f[i].type=='D'&&t2<=f[i].cost)
continue;
if(f[i].type=='C'&&t1>f[i].cost) {
t1-=f[i].cost;
cnt=0;
cnt+=f[i].b;
} else if(f[i].type=='D'&&t2>f[i].cost) {
t2-=f[i].cost;
cnt=0;
cnt+=f[i].b;
}
for(int j=i+1; j<n; j++) {
if(f[j].type=='C'&&f[j].cost<=t1) {
cnt+=f[j].b;
maxs=max(maxs,cnt);
break;
} else if(f[j].type=='D'&&f[j].cost<=t2) {
cnt+=f[j].b;
maxs=max(maxs,cnt);
break;
}
}
}
printf("%d\n",max(maxs,maxxn));
}
return 0;
}
Fountains(非线段树版(主要是不太会用))的更多相关文章
- Matrix(线段树版)
poj2155:http://poj.org/problem?id=2155 题意;同上一遍随笔. 题解:这里用二维线段树打了一发.第一次学习别人的代码.才学的.这种树套树的程序,确实很费脑子,一不小 ...
- BZOJ2028:[SHOI2009]会场预约(线段树版)
浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:https://www.lydsy.com/JudgeOnline/prob ...
- Color the ball HDU - 1556 (非线段树做法)
题意:在1到n的气球中,在不同的区域中涂颜色,问每个气球涂几次. #include<cstdio>int num[100010];int main(){ int n, x, y;; whi ...
- hdu 1556 Color the ball(非线段树做法)
#include<stdio.h> #include<string.h> ]; int main() { int n,i; int a,b; while(scanf(" ...
- ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】
FZU 2105 Digits Count Time Limit:10000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- zkw线段树详解
转载自:http://blog.csdn.net/qq_18455665/article/details/50989113 前言 首先说说出处: 清华大学 张昆玮(zkw) - ppt <统计的 ...
- Luogu P3740 [HAOI2014]贴海报_线段树
线段树版的海报 实际上这个与普通的线段树相差不大,只是貌似数据太水,暴力都可以过啊 本来以为要离散的,结果没打就A了 #include<iostream> #include<cstd ...
- 洛谷.3733.[HAOI2017]八纵八横(线性基 线段树分治 bitset)
LOJ 洛谷 最基本的思路同BZOJ2115 Xor,将图中所有环的异或和插入线性基,求一下线性基中数的异或最大值. 用bitset优化一下,暴力的复杂度是\(O(\frac{qmL^2}{w})\) ...
- Gym 101911E "Painting the Fence"(线段树区间更新+双端队列)
传送门 题意: 庭院中有 n 个围栏,每个围栏上都被涂上了不同的颜色(数字表示): 有 m 条指令,每条指令给出一个整数 x ,你要做的就是将区间[ x第一次出现的位置 , x最后出现的位置 ]中的围 ...
随机推荐
- js的两种查询方式 LHS and RHS
为了进一步理解,我们需要多介绍一点编译器的术语.编译器在编译过程的第二步中生成了代码,引擎执行它时,会通过查找变量 a 来判断它是否已声明过.查找的过程由作用域进行协助,但是引擎执行怎样的查找,会影响 ...
- Hyperledger Fabric Orderer节点启动
Orderer 节点启动通过 orderer 包下的 main() 方法实现,会进一步调用到 orderer/common/server 包中的 Main() 方法. 核心代码如下所示. // Mai ...
- JavaScript——Dom编程(1)
DOM:Document Object Model(文本对象模型) D:文档 – html 文档 或 xml 文档O:对象 – document 对象的属性和方法M:模型 DOM 是针对xml(htm ...
- A. Xor-tree
题目意思: 给一颗n个节点的树,每个节点有一个值要么是0要么是1,改变某个节点的值时,它的儿子不变,它儿子的儿子翻转,它儿子的儿子的儿子不变,如此类推.给定各个节点的目标值,求最少的翻转次数,使得达到 ...
- Appium混合应用测试
Appium测试混合应用 混合应用即是原生应用中间混着html页面,需要在两种类型的页面之间跳转. 测试Android混合应用 前期设置 4.4以下版本使用automationName:Selendr ...
- (转)jQuery基础之选择器
原文地址: http://www.cnblogs.com/webmoon/p/3169360.html 选择器是jQuery的根基,在jQuery中,对事件处理.遍历DOM和Ajax操作都依赖于选择器 ...
- 【Head First Java 读书笔记】(一)基本概念
Java的工作方式 你要做的事情就是会编写源代码 Java的程序结构 类存于源文件里面 方法存在类中 语句存于方法中 剖析类 当Java虚拟机启动执行时,它会寻找你在命令列中所指定的类,然后它会锁定像 ...
- Python htmlTestRunner生成测试报告Demo
#该代码段是ReadTxt_demo.py 的代码,用户读取txt 文件中的用户信息. #ReadTxt_demo.py def readTxt(filePath): fo = open(filePa ...
- delphi 指针 认识
delphi 指针分为类型指针和无类型指针: 类型指针分为PChar.PInteger.PString等. 无类型指针Pointer. PPChar/PP...为指针的指针 @和Addr一样,为获取变 ...
- asp.net get图
前段 <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat=& ...