Codeforces Round #413 (Div1 + Div. 2) C. Fountains(树状数组维护最大值)
题目链接: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(树状数组维护最大值)的更多相关文章
- 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 ...
- 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 ...
- 树状数组 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 ...
- 贪心+树状数组维护一下 Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) D
http://codeforces.com/contest/724/problem/D 题目大意:给你一个串,从串中挑选字符,挑选是有条件的,按照这个条件所挑选出来的字符集合sort一定是最后选择当中 ...
- Codeforces Gym 100269F Flight Boarding Optimization 树状数组维护dp
Flight Boarding Optimization 题目连接: http://codeforces.com/gym/100269/attachments Description Peter is ...
- 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 ...
- 【预处理】【分类讨论】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains
分几种情况讨论: (1)仅用C或D买两个 ①买两个代价相同的(实际不同)(排个序) ②买两个代价不同的(因为买两个代价相同的情况已经考虑过了,所以此时对于同一个代价,只需要保存美丽度最高的喷泉即可)( ...
- 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 ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) E - Aquarium decoration 贪心 + 平衡树
E - Aquarium decoration 枚举两个人都喜欢的个数,就能得到单个喜欢的个数,然后用平衡树维护前k大的和. #include<bits/stdc++.h> #define ...
随机推荐
- poj1056(字符串判断是否存在一个字符串是另一个字符串的前缀)
题目链接:https://vjudge.net/problem/POJ-1056 题意:给定一个字符串集,判断是否存在一个字符串是另一个字符串的前缀. 思路:和hdoj1671一样,有两种情况: 当前 ...
- [Asp.Net Core] - 设置 Syncfusion / RichTextEditor 移除超链接及高度自适应 的方法
背景 使用 Syncfusion / RichTextEditor 对录入后的信息进行展示:1. 希望内容高度自适应.2. 希望禁用原文中的超链接. 实现 <div class=" ...
- git config 介绍
转载. https://blog.csdn.net/liuxiao723846/article/details/83113317 Git的三个重要配置文件分别是/etc/gitconfig,${HOM ...
- C++ 中的 多态性
一 .多态性 1.多态性概述:多态是指同样的消息被不同类型的对象接受时导致不同的行为 2.多态实现:编译时的多态:在编译的过程中确定了同名操作的具体对象. 运行时的多态:在程序运行过程中动态地确定 ...
- Linux 进程控制
分享知乎上看到的一句话,共勉: 学习周期分为学习,思考,实践,校正四个阶段,周期越短,学习效率越高. 前面讲的都是操作系统如何管理进程,接下来,看看用户如何进行进程控制. 1.进程创建 先介绍一下函数 ...
- Golang的安装与环境配置(包括Go lint、Go imports、Go fmt)
Golang安装 下载地址:https://studygolang.com/dl Go语言中文网 下载后安装,win10系统中会自动配置大部分设置,linux系统请参照网上教程 GO环境变量配置: $ ...
- Golang安装和配置
Golang安装和配置 Linux Golang 下载源码,解压. # /home/superpika为你的主目录 mkdir /home/superpika/go mkdir /home/super ...
- java redisUtils工具类很全
GitHub地址:https://github.com/whvcse/RedisUtil redisUtils工具类: package com.citydo.utils; import org.spr ...
- IDEA解决 lombok 编译报错 cannot resolve method set/get 方法
首先关于lombok的介绍 https://blog.csdn.net/ThinkWon/article/details/101392808 总之,就是通过添加注解的方式,不需要为类编写getter或 ...
- CSS Cursor屬性 (光标停留显示)
<html> <body> <p>请把鼠标移动到单词上,可以看到鼠标指针发生变化:</p> <span style="cursor:au ...