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. xutils3文件上传、下载、get、post请求

    @ContentView(R.layout.activity_xutils3_net) public class XUtils3NetActivity extends Activity { @View ...

  2. 搭建SSM项目时报错(org.springframework.jdbc.CannotGetJdbcConnectionException)

    严重: Servlet.service() for servlet [SpringMVC] in context with path [/ssm] threw exception [Request p ...

  3. [原创]java WEB学习笔记37:EL表达式(简介,运算符,自动类型转换,保留字,隐含对象)

    1.EL 简介 1)EL 全名为 Expression  Language,它原本是 JSTL  1.0 为方便存取数据所自定义的语言 2)语法:EL 语法很简单,它最大的特点就是使用上很方便:${s ...

  4. 【leetcode刷题笔记】Spiral Matrix

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...

  5. jQuery悬浮焦点图宽屏

    在线演示 本地下载

  6. hbase shell-general(常规指令)

    hbase shell常规指令解释篇 1. status (显示集群状态,master,server情况,显示内容的详略程度可选) hbase(main)::> help 'status' Sh ...

  7. 算法(Algorithms)第4版 练习 1.4.6

    (1)sum = N + N/2 + N/4 +  …… + 1 假设N是2的倍数(N = 2q),则sum = N -1 ~ N (2)sum = 1+2+……N/2 同(1)分析,sum = N/ ...

  8. JS中不同类型的值比较问题

    我们比较数据的时候大多是以下两种情况: 3 > 4 ; "m" > "n" ; 但有时候可能会出现比较符号两侧的数据类型不相同的场景,例如 5 &g ...

  9. nginx+tomcat负载均衡搭建

    一.      单独部署tomcat和nginx Nginx版本:nginx-1.13.5 Tomcat版本:apache-tomcat-8.5.8 操作系统:win10 必须先部署一个tomcat服 ...

  10. Oracle的PL_SQL的结构

    --PL/SQL的结构 declare --声明变量和常量关键字 v_name nvarchar2(); v_age integer;--常规变量声明 v_product table_name.col ...