Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains 【树状数组维护区间最大值】
题目传送门:http://codeforces.com/contest/799/problem/C
C. Fountains
2 seconds
256 megabytes
standard input
standard output
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.
Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.
Input
The first line contains three integers n, c and d (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100 000) — the number of fountains, the number of coins and diamonds Arkady has.
The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 ≤ bi, pi ≤ 100 000) — the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.
Output
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
3 7 6
10 8 C
4 3 C
5 6 D
9
2 4 5
2 5 C
2 1 D
0
3 10 10
5 5 C
5 5 C
10 11 D
10
Note
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.
In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins.
题目大意:
有 N 个水池,每个水池有 观赏值 和 花费(金币或者钻石);Arkady有 C 个金币 D 个钻石,他想建两个水池,使得观赏值最高。
解题思路:
树状数组维护金币和钻石花费范围内所能得到的最大值,每次输入都比较三种可能性一个金币的一个钻石的,两个金币的,两个钻石的。
AC code:
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define ll long long int
using namespace std; const int MAXN = 1e5+; int t_1[MAXN], t_2[MAXN];
int N, num_c, num_d; int lowbit(int x)
{
return x&(-x);
}
void add(int no, int st, int value)
{
for(int i = st; i <= MAXN; i+=lowbit(i))
{
if(no) t_1[i] = max(t_1[i], value);
else t_2[i] = max(t_2[i], value);
}
} int query(int no, int st)
{
int res = ;
for(int i = st; i > ; i-=lowbit(i))
{
if(no) res = max(res, t_1[i]);
else res = max(res, t_2[i]);
}
return res;
}
int main()
{
char str[];
int ans_max = , a, b, ans = ;
scanf("%d%d%d", &N, &num_c, &num_d);
for(int i = ; i <= N; i++)
{
scanf("%d%d", &a, &b);
scanf("%s", str);
if(str[] == 'C'){
ans_max = query(, num_d);
if(b > num_c) continue;
ans_max = max(ans_max, query(, num_c-b));
add(, b, a);
}
else{
ans_max = query(, num_c);
if(b > num_d) continue;
ans_max = max(ans_max, query(, num_d-b));
add(, b, a);
}
if(ans_max) ans = max(ans, ans_max+a);
}
printf("%d\n", ans);
return ;
}
Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains 【树状数组维护区间最大值】的更多相关文章
- 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 ...
- 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) 一夜回到小学生
我从来没想过自己可以被支配的这么惨,大神讲这个场不容易掉分的啊 A. Carrot Cakes time limit per test 1 second memory limit per test 2 ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) E - Aquarium decoration 贪心 + 平衡树
E - Aquarium decoration 枚举两个人都喜欢的个数,就能得到单个喜欢的个数,然后用平衡树维护前k大的和. #include<bits/stdc++.h> #define ...
- 【动态规划】【滚动数组】【搜索】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion
显然将扩张按从大到小排序之后,只有不超过前34个有效. d[i][j]表示使用前i个扩张,当length为j时,所能得到的最大的width是多少. 然后用二重循环更新即可, d[i][j*A[i]]= ...
- 【预处理】【分类讨论】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) C. Fountains
C. Fountains time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion
D. Field expansion time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #425 (Div. 2) D 树链剖分 + 树状数组维护区间
一看就知道 可以LCA判断做 也可以树链剖分拿头暴力 然而快速读入和线段树维护区间会T70 于是只能LCA? 线段树的常数不小 于是需要另外一种办法来进行区间加减和查询区间和 就是使用树状数组 这个题 ...
随机推荐
- 2019.03.27 读书笔记 关于GC垃圾回收
在介绍GC前,有必要对.net中CLR管理内存区域做简要介绍: 1. 堆栈:用于分配值类型实例.堆栈主要操作系统管理,而不受垃圾收集器的控制,当值类型实例所在方法结束时,其存储单位自动释放.栈的执行效 ...
- [转]sudo: sorry, you must have a tty to run sudo问题
使用不同账户,执行执行脚本时候sudo经常会碰到 sudo: sorry, you must have a tty to run sudo这个情况,其实修改一下sudo的配置就好了vi /etc/su ...
- PHP流程控制之goto语句
goto 操作符可以用来跳转到程序中的另一位置.该目标位置可以用目标名称加上冒号来标记,而跳转指令是 goto 之后接上目标位置的标记.PHP 中的 goto 有一定限制,目标位置只能位于同一个文件和 ...
- jQuery 菜单小练习(实现点击和移动鼠标效果)
这个代码的练习是点击事件后 如何用jQuery联动的方式找到相关标签 实现的结果是点击菜单一或者菜单二等 会出现相关菜品,并隐藏其他菜品.鼠标移动才菜品上会在右侧框内出现相关菜品的价格.实现特殊的效果 ...
- 图像文字识别(OCR)用什么算法小结
说明:主要考虑深度学习的方法,传统的方法不在考虑范围之内. 1.文字识别步骤 1.1detection:找到有文字的区域(proposal). 1.2classification:识别区域中的文字. ...
- 【Iftop】实时监控流量工具
linux基本查询流量的命令有: 1.ifconfig 只能看到当前接收和发送出去的总共的字节大小,但是不能看到网卡流量的实时发送情况 2.watch more /proc/net/dev 只有接受 ...
- windows下快速修改host文件
windows下快速修改host文件 win+r 输入 notepad c:\Windows\System32\drivers\etc\hosts
- A bug about RecipientEditTextView
- Steps to reproduce the problem. Pre-condition:the threshold of the RecipientEditTextView is set to ...
- Java集合篇六:Map中key值不可重复的测试
package com.test.collection; import java.util.HashMap; import java.util.Map; //Map中key值不可重复的测试 publi ...
- css之margin,padding的百分比
注意:上下内边距与左右内边距一致:即上下内边距的百分数会相对于父元素宽度设置,而不是相对于高度. PS:而且是基于父元素内容的宽度(width属性的大小),不是基于父元素整个框架的宽度