http://codeforces.com/contest/799/problem/C

解题关键:树状数组取最大值,注意先搜索,后加入,此种情况可以取出最大值。

为什么可以取到最大值?

1、当分别用两种硬币购买时,一定可以全部访问完。

2、用一种硬币时, 依然可以遍历完

 #include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;//要建两颗树状数组
int C[],D[],maxn=;
int read(int *tree,int i){
int s=;
while(i>){
s=max(s,tree[i]);
i-=i&-i;
}
return s;
}
void add(int *tree,int i,int x){
while(i<=maxn){
tree[i]=max(tree[i],x);
i+=i&-i;
}
}
//必须先搜索,再加入
int b,p;
char a;
int main(){
int n,c,d,mm,ans=;
cin>>n>>c>>d;
fo(i,,n){
cin>>b>>p>>a;
if(a=='C'){
mm=read(D,d);
if(p>c) continue;
mm=max(mm,read(C,c-p));
add(C,p,b);
}
else{
mm=read(C,c);
if(p>d) continue;
mm=max(mm,read(D,d-p));
add(D,p,b);
}
if(mm){
ans=max(ans,mm+b);
}
}
cout<<ans<<endl;
}

[#413c] Fountains的更多相关文章

  1. Fountains(非线段树版(主要是不太会用))

    Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available foun ...

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

    题目传送门:http://codeforces.com/contest/799/problem/C C. Fountains time limit per test 2 seconds memory ...

  3. codeforces 799C Fountains

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

  4. 树状数组 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 ...

  5. codeforces 799 C. Fountains(二分+思维)

    题目链接:http://codeforces.com/contest/799/problem/C 题意:要求造2座fountains,可以用钻石,也可以用硬币来造,但是能用的钻石有限,硬币也有限,问能 ...

  6. CodeForce-799C Fountains (记忆化DP)

    Fountains CodeForces - 799C 某土豪想要造两座喷泉.现在有 n 个造喷泉的方案,我们已知每个方案的价格以及美观度.有两种合法的货币:金币和钻石.这两种货币之间不能以任何方式转 ...

  7. Codeforces Round #413, rated, Div. 1 + Div. 2 C. Fountains(贪心 or 树状数组)

    http://codeforces.com/contest/799/problem/C 题意: 有n做花园,有人有c个硬币,d个钻石 (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100  ...

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

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

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

随机推荐

  1. rails member collection

    resources :theses do resources :document do get :download, :on => :member end end <a class=&qu ...

  2. 3.11课·········异常语句与for循环重复

    异常语句try catch finally try//保护执行里面的代码段,若其中一句有错误,直接跳转到catch,不会管下面的内容 { Console.Write("请输入一个整数&quo ...

  3. LeetCode:二叉树的前、中、后序遍历

    描述: ------------------------------------------------------- 前序遍历: Given a binary tree, return the pr ...

  4. Android硬件抽象层(HAL)概要介绍【转】

    本文转载自:http://blog.csdn.net/luoshengyang/article/details/6567257 Android的硬件抽象层,简单来说,就是对Linux内核驱动程序的封装 ...

  5. <linux报错解决>在Fedora21下安装vmware报错的解决办法

    关于VMWARE WORKSTATION在Fedora21下的安装问题 (1)在Fedora21下安装vmware如果在终端下启动,提示你找不到内核头文件Kernel Headers的话使用命令: s ...

  6. 算法(Algorithms)第4版 练习 1.3.2

    was best times of the was the it (1 left on stack)

  7. cdoj 1256 昊昊爱运动 预处理

    昊昊爱运动 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) 昊昊喜欢运动 他NN ...

  8. springmvc接受表单多条数据的值

    点击下面链接查看具体内容: http://blog.csdn.net/lutinghuan/article/details/46820023

  9. node.js+express+jade系列七:富文本编辑框的使用

    下载nicEdit富文本编辑框, 把nicEdit.js文件放到public/javascripts/下 新建jade文件:代码如下 doctype htmlhtml    head        t ...

  10. Git_学习_00_资源帖

    1.廖雪峰: (1)Git教程 2.阮一峰: (1)Git分支管理策略 (2)Git远程操作详解 (3)Git 使用规范流程 (4)Github 的清点对象算法 (5)常用 Git 命令清单 (6)G ...