【CodeForces - 799C】【Fountains】

本文深入探讨了游戏开发中资源管理的重要性,分享了一系列优化技巧,包括如何有效利用内存,减少加载时间,以及提高游戏性能的方法。通过实例分析,帮助开发者理解和掌握资源管理的核心概念,提升游戏质量和用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目:

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 nc 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.

Examples

Input

3 7 6
10 8 C
4 3 C
5 6 D

Output

9

Input

2 4 5
2 5 C
2 1 D

Output

0

Input

3 10 10
5 5 C
5 5 C
10 11 D

Output

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,然后和两种货币的拥有数目,之后输入n行数据,解释每个井的情况,咱们要在已有资产的前提下,求出两个井的最大美值。

解题思路:刚上来是想直接按照魅力值降序排列一下,之后直接找满足条件的两个井,但是会wa 因为这样做只是考虑的一种比较简单的情况假设数据为 3 10 5   , 9 9 C,5 5 C, 5 6 C。这样输出9而不是正确的11 。 所以,为了解决这个问题 ,决定开树状数组来求解。实时更新树状数组的值,以花费为下标,魅力值为数值。

ac代码:

#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define maxn 100010
int n,c,d;
struct node{
	int bea,p;
};
struct node cc[maxn],dd[maxn];
int tt[maxn];
int lowbit(int x)
{
	return x&-x;
}
int query(int x)
{
	int ans=0;
	while(x>0)
	{
		ans=max(ans,tt[x]);
		x-=lowbit(x);
	}
	return ans;
}
void updata(int x,int y,int val)
{
	while(x<y)
	{
		tt[x]=max(tt[x],val);
		x+=lowbit(x);
	}
}
int main()
{
	while(scanf("%d%d%d",&n,&c,&d)!=EOF)
	{
		int cnt1=0,cnt2=0;
		int ans1=-1,ans2=-1;
		for(int i=0;i<n;i++)
		{
			int b,p;
			char s;
			cin>>b>>p>>s;
			if(s=='C')
			{
				if(p<=c)
				{
				cc[cnt1].bea=b;
				cc[cnt1++].p=p;
				ans1=max(ans1,b);
				}
			}
			else
			{
				if(p<=d)
				{
				dd[cnt2].bea=b;
				dd[cnt2++].p=p;
				ans2=max(ans2,b);
				}
			}
		}
		int ans=0;
		if(ans1!=-1&&ans2!=-1)
			ans=ans1+ans2;
		memset(tt,0,sizeof(tt));
		for(int i=0;i<cnt1;i++)
		{
			int cur=query(c-cc[i].p);
			if(cur>0)
			{
				ans=max(ans,cur+cc[i].bea);
			}
			updata(cc[i].p,maxn,cc[i].bea);
		}
		memset(tt,0,sizeof(tt)); 
		for(int i=0;i<cnt2;i++)
		{
			int cur=query(d-dd[i].p);
			if(cur>0)
			{
				ans=max(ans,cur+dd[i].bea);
			}
			updata(dd[i].p,maxn,dd[i].bea);
		}
		printf("%d\n",ans);
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值