Codeforces - Fountains

題目鏈接:Codeforces - Fountains


做法挺多的。

直接枚舉當前選的一個,然後另一個從前面選即可。

然後動態維護前綴max,Fenwick tree即可。

注意要麼不選,要麼就要選2個。


AC代碼:

#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1e5+10;
int n,c,d,res; char op[2];
struct Fenwick{
	int d[N],up=1e5;
	Fenwick(){for(int i=1;i<=up;i++)	d[i]=-1e9;}
	void insert(int x,int v){for(;x<=up;x+=x&(-x)) d[x]=max(d[x],v);}
	int ask(int x){int s=-1e9; for(;x;x-=x&(-x)) s=max(s,d[x]); return s;}
}dc,dd;
signed main(){
	cin>>n>>c>>d;
	for(int i=1,b,p;i<=n;i++){
		scanf("%d %d %s",&b,&p,op);
		if(op[0]=='C'){
			if(p>c)	continue;
			res=max(res,b+max(dc.ask(c-p),dd.ask(d)));
			dc.insert(p,b);
		}else{
			if(p>d)	continue;
			res=max(res,b+max(dc.ask(c),dd.ask(d-p)));
			dd.insert(p,b);
		}
	}
	cout<<res;
	return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章