Codeforces Fountains

Cross Fire!

题目大意:有一些喷泉,分为两种,一种只可以硬币购买,一种只可以用钻石购买,它们都有各自的价值,现在你有一些钻石和硬币,要买两座喷泉,问最大可获得的价值。

解题思路:其实思路挺好出,就是复杂度不够,用树状数组优化即可

感觉下一次出这样的我还是不会呀嘤嘤嘤

代码:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#define FAST ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)1e5 + 5;
using namespace std;

//需要维护最大值
//循环判断显然会超时
//树状数组操作

int a[maxn], b[maxn];

int sum(int *t, int x){
	int ret = 0;
	for( ; x > 0; ret = max(ret, t[x]), x -= lowbit(x));//维护的是最大值,不再是和了
	return ret;
}

void update(int *t, int x, int val){
	for( ; x <= maxn; t[x] = max(t[x], val), x += lowbit(x));//同
}

int main()
{
	int n, c, d; scanf("%d %d %d", &n, &c, &d);
	int ans = 0;
	for(int i = 1; i <= n; i++){
		int val, w; scanf("%d %d ", &val, &w);
		char type; scanf("%c", &type);
		int Max = 0;
		if(type == 'C'){//分别维护
			Max = sum(b, d);
			if(w > c) continue;
			Max = max(Max, sum(a, c - w)); //更新,维护Max
			update(a, w, val);
		}
		else{//
			Max = sum(a, c);
			if(w > d) continue;
			Max = max(Max, sum(b, d - w));
			update(b, w, val);
		}
		if(Max) ans = max(Max + val, ans);
	}
	printf("%d\n", ans);
	return 0;
}

over

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值