题目链接: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. From 虚拟机模板 创建单节点K8S1.14.1的操作步骤

    半年前总结的 还是有记不住的地方... 1. 根据上一篇blog 自己创建了一个虚拟机 里面包含 k8s1.14.1 的k8s集群 这里简单说一下 虚拟机开机之后 如何处理以能够使用k8s 的简单过程 ...

  2. [C#] - 从 HTML 代码中 转换 / 提取 可读文字(PlainText)的方法

    背景 在做网页数据分析的时候,我们关注的部分是内容,可以过滤掉HTML标签.Javascript.CSS等代码. 目标输入 <b>Hello World.</b><br/ ...

  3. Word 带圈字符 1~20 快捷键的输入的技巧

    1. 前言 如何在Word中输入带圈数字?为大家分享一种快速录入带圈字符的方法,就是使用快捷键. 2. 输入带圈字符 1.在Word中输入2465,然后使用快捷键「ALT + X」就能变成⑥:输入24 ...

  4. Python-04-数据结构

    一.数字 整数 Python可以处理任意大小的整数,当然包括负整数,在程序中的表示方法和数学上的写法一模一样,例如:1,100,-8080,0,等等. 计算机由于使用二进制,所以,有时候用十六进制表示 ...

  5. Shiro授权及注解式开发

    目的: shiro授权 shiro注解式开发 Shiro授权 首先设计shiro权限表: 从图中我们也清晰的看出五张表之间的关系 ShiroUserMapper Set<String> g ...

  6. 音视频入门-13-使用开源库生成PNG图片

    * 音视频入门文章目录 * RGB-to-PNG 回顾 上一篇 [手动生成一张PNG图片] 根据 [PNG文件格式详解] 一步一步地手动实现了将 RGB 数据生成了一张 PNG 图片. 有许多开源的 ...

  7. Python通用爬虫,聚焦爬虫概念理解

    通用爬虫:百度.360.搜狐.谷歌.必应....... 原理: (1)抓取网页 (2)采集数据 (3)数据处理 (4)提供检索服务 百度爬虫:Baiduspider 通用爬虫如何抓取新网站? (1)主 ...

  8. vs2015工程转化为vs2010

    转换的步骤如下: (1)将工程是.sln用记事本打开后,更换以下信息如下:   Microsoft Visual Studio Solution File, Format Version 11.00 ...

  9. 微信小程序通讯录字母排序

    微信小程序通讯录 字母排序效果: demo地址:https://github.com/PeachCoder/wechat-contacts

  10. 3_PHP表达式_4_PHP运算符

    以下为学习孔祥盛主编的<PHP编程基础与实例教程>(第二版)所做的笔记. 3.4.1 算术运算符 <?php $num1 = -10; $num2 = -4; $num3 = $nu ...