题目链接:https://codeforces.com/problemset/problem/799/C

题意:有 c 块硬币和 d 块钻石,每种喷泉消耗硬币或钻石中的一种,每个喷泉有一个美丽值,问建造两个喷泉可以获得的最大美丽值是多少。

题解:三种情况:买两个消耗硬币的喷泉,买两个消耗钻石的喷泉或各买一个,消耗的范围是1e5,故用树状数组维护之前的最大值,考虑加入当前建造的更新答案。

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi acos(-1)
#define pii pair<int,int>
#define pb push_back
#define lowbit(x) ((x)&(-x))
const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const int maxn = 1e5 + ;
const int maxm = 1e6 + ;
const ll mod = ; void add(int a[],int pos,int val) {
while(pos < maxn) {
a[pos] = max(a[pos],val);
pos += lowbit(pos);
}
} int query(int a[],int pos) {
int ans = ;
while(pos) {
ans = max(ans,a[pos]);
pos -= lowbit(pos);
}
return ans;
} int a[maxn],b[maxn]; int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int n,c,d;
scanf("%d%d%d",&n,&c,&d);
int ans = ;
for(int i = ; i < n; i++) {
int bea,cost;
char s[];
scanf("%d%d%s",&bea,&cost,s);
int mx = ;
if(s[] == 'C') {
if(cost > c) continue;
int can = query(b,d);
if(can) mx = bea + query(b,d);
can = query(a,c - cost);
if(can) mx = max(mx, bea + can);
add(a,cost,bea);
} else {
if(cost > d) continue;
int can = query(a,c);
if(can) mx = bea + query(a,c);
can = query(b,d - cost);
if(can) mx = max(mx, bea + can);
add(b,cost,bea);
}
ans = max(ans, mx);
}
printf("%d\n",ans);
return ;
}

Codeforces Round #413 (Div1 + Div. 2) C. Fountains(树状数组维护最大值)的更多相关文章

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

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

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

  4. 贪心+树状数组维护一下 Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) D

    http://codeforces.com/contest/724/problem/D 题目大意:给你一个串,从串中挑选字符,挑选是有条件的,按照这个条件所挑选出来的字符集合sort一定是最后选择当中 ...

  5. Codeforces Gym 100269F Flight Boarding Optimization 树状数组维护dp

    Flight Boarding Optimization 题目连接: http://codeforces.com/gym/100269/attachments Description Peter is ...

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

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

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

  8. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)(A.暴力,B.优先队列,C.dp乱搞)

    A. Carrot Cakes time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...

  9. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) E - Aquarium decoration 贪心 + 平衡树

    E - Aquarium decoration 枚举两个人都喜欢的个数,就能得到单个喜欢的个数,然后用平衡树维护前k大的和. #include<bits/stdc++.h> #define ...

随机推荐

  1. oracle加密--wallet

    SQL> SELECT * FROM V$ENCRYPTION_WALLET; WRL_TYPE WRL_PARAMETER STATUS -------------------- ------ ...

  2. django使用pyecharts(1)----django加入echarts

    Django 中使用 pyecharts.一.普通django加入echarts Django 模板渲染 Step 0: 新建一个 Django 项目 $ django-admin startproj ...

  3. python学习-57 logging模块

    logging 1.basicConfig方式 import logging # 以下是日志的级别 logging.debug('debug message') logging.info('info ...

  4. Python Http-server 使用

    Python内置的下载服务器 http.server  Python的Web服务器 python2 中SimpleHTTPServer python3 中 http.server 执行 python ...

  5. Java同C#的语法不同之处

    Java同C#的语法不同之处... [注:转载而来但原出处不详:若是您原创请联系我]1,命名空间与包 C#为了把实现相似功能的类组织在一起,引入了命名空间的概念(namespace) Java中与此对 ...

  6. (转)FFMPEG 实现 YUV,RGB各种图像原始数据之间的转换(swscale)

    雷霄骅分类专栏: FFMPEG FFmpeg 本文链接:https://blog.csdn.net/leixiaohua1020/article/details/14215391 FFMPEG中的sw ...

  7. DG环境恢复同步遇到报错ORA-00353ORA-00334以及ORA-00600[2619], [47745]

    问题说明 客户环境主库4节点RAC11.2.0.4,单实例DG环境,DG由于空间不足,导致同步中断,由于DG备库未应用的归档主库都再,本次恢复的方式,是开启dg mrp进程,自动同步追上主库. 以下遇 ...

  8. 既有设计模式的lambda重构

    设计模式的博客要有模式的定义,UML类图,代码实现和模式的优缺点, 策略模式 工厂模式 模版方法 观察者模式 责任链模式 1 策略模式:定义了一组算法,并将每一个算法封装起来,使它们每一个之间可以相互 ...

  9. ExcelReport.cs Excel操作类、实例源码下载

    标题一.告别ASP.NET操作EXCEL的烦恼标题二.ASP.NET操作EXCEL 合并单元格 大全... cnblogs/hanzhaoxin/韩兆新的博客园ExcelReport第一篇:使用Exc ...

  10. Ubuntu install android studio

    Ubuntu install android studio 1. 安装 openjdk8,并在配置文件 /etc/profile 中,追加如下内容: sudo aptitude install ope ...