【预处理】【分类讨论】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains
分几种情况讨论:
(1)仅用C或D买两个
①买两个代价相同的(实际不同)(排个序)
②买两个代价不同的(因为买两个代价相同的情况已经考虑过了,所以此时对于同一个代价,只需要保存美丽度最高的喷泉即可)(预处理b[i],表示代价小于等于i的物品中,美丽度最大的是多少。为了防止重复购买,枚举其中一个,然后另一个只买代价小于其代价的物品。)
(2)用C和D各买一个
按这几种情况分类,可以比较好地避免买到同一个喷泉的情况。
#include<cstdio>
#include<algorithm>
using namespace std;
int n,c,d,b[100010],p[100010];
char op[100010][3];
struct data{
int v,c;
}a1[100010],a2[100010];
int b1[100010],b2[100010];
bool operator < (const data &a,const data &b){
return a.c!=b.c ? a.c<b.c : a.v<b.v;
}
int ans=0;
int main(){
// freopen("c.in","r",stdin);
scanf("%d%d%d",&n,&c,&d);
int m1=0,m2=0;
for(int i=1;i<=n;++i){
scanf("%d%d%s",&b[i],&p[i],op[i]);
if(op[i][0]=='C'){
a1[++m1]=(data){b[i],p[i]};
}
else{
a2[++m2]=(data){b[i],p[i]};
}
}
sort(a1+1,a1+m1+1);
for(int i=2;i<=m1;++i){
if(a1[i].c==a1[i-1].c && a1[i].c*2<=c){
ans=max(ans,a1[i].v+a1[i-1].v);
}
}
for(int i=1;i<=m1;++i){
b1[a1[i].c]=max(b1[a1[i].c],a1[i].v);
}
for(int i=1;i<=c;++i){
b1[i]=max(b1[i],b1[i-1]);
}
for(int i=1;i<=m1;++i){
if(a1[i].c<=c && b1[min(c-a1[i].c,a1[i].c)-(a1[i].c<=c-a1[i].c)]){
ans=max(ans,a1[i].v+b1[min(c-a1[i].c,a1[i].c)-(a1[i].c<=c-a1[i].c)]);
}
} sort(a2+1,a2+m2+1);
for(int i=2;i<=m2;++i){
if(a2[i].c==a2[i-1].c && a2[i].c*2<=d){
ans=max(ans,a2[i].v+a2[i-1].v);
}
}
for(int i=1;i<=m2;++i){
b2[a2[i].c]=max(b2[a2[i].c],a2[i].v);
}
for(int i=1;i<=d;++i){
b2[i]=max(b2[i],b2[i-1]);
}
for(int i=1;i<=m2;++i){
if(a2[i].c<=d && b2[min(d-a2[i].c,a2[i].c)-(a2[i].c<=d-a2[i].c)]){
ans=max(ans,a2[i].v+b2[min(d-a2[i].c,a2[i].c)-(a2[i].c<=d-a2[i].c)]);
}
} if(b1[c] && b2[d]){
ans=max(ans,b1[c]+b2[d]);
} printf("%d\n",ans);
return 0;
}
【预处理】【分类讨论】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) C. Fountains 【树状数组维护区间最大值】
题目传送门:http://codeforces.com/contest/799/problem/C C. Fountains time limit per test 2 seconds memory ...
- 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
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 #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 ...
随机推荐
- input file 文件上传,js控制上传文件的大小和格式
文件上传一般是用jquery的uploadify,比较好用.后面会出文章介绍uploadify这个插件. 但是,有时候为了偷懒,直接就用input 的file进行文件和图片等的上传,input fil ...
- Perl6 Bailador框架(8):自定义400/500
第一种方法, 直接写在源码中: use Bailador; get '/' => sub { '<h1>hello, Bailador</h1>'; } get '/te ...
- perl6 修改文件并覆盖
use v6; my $filename = 'data.txt'; my $data = slurp $filename; say $data; $data ~~ s/'4'/'ABC'/; say ...
- SQL语句语法简介
SQL命令一般分为DQL.DML.DDL几类: DQL:数据查询语句,基本就是SELECT查询命令,用于数据查询 DML:Data Manipulation Language的简称,即数据操纵语言,主 ...
- TCP之connect
1. connect函数: #include <sys/socket.h> int connect(int sockfd, const struct sockaddr *servaddr, ...
- 神秘的subsys_initcall【转】
转自:http://blog.chinaunix.net/uid-12567959-id-161015.html 在内核代码里到处都能看到这个subsys_initcall(),而它到底是干什么的呢? ...
- RemoteBox 1.6 发布,VirtualBox 管理工具
RemoteBox 1.6 发布,VirtualBox 管理工具 http://www.lupaworld.com/article-230113-1.html 安装VirtualBox Extensi ...
- 【LA3882】And then there was one
做sb题也是一种乐趣,是吧…… #include<bits/stdc++.h> #define N 10005 using namespace std; int f[N],m,n,k; i ...
- 离线安装SDK
1.下载android-sdk_rXX-windows.zip(XX为版本号,也可以下.exe版的不过没试过) 2.下载SDK 2.1.在浏览器输入http://dl-ssl.google.com/a ...
- servlet为什么要配置web.xml
(1).为Servlet命名: <servlet> <servlet-name>servlet1</servlet-name> <- 这是用于,在serv ...