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
output
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 nc and d (2 ≤ n ≤ 100 0000 ≤ 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个喷泉,每个喷泉有个漂亮值和价格以及你能用哪种货币买,

问用已拥有的货币你买两个喷泉,最大漂亮值多少

必须要买两个,买不起两个就是0

价格的范围很小,可以开个数组dp【i】记录i货币可以买的最大价值

乱搞一下就可以了


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
struct node
{
	int p,b;
}cc[100050],dd[100050];
int dp[2][100050];
int cmp(node a,node b)
{
	return a.b<b.b;
}
int main()
{
	int n,c,d,p,b,i,j;
	int nc=0,nd=0;
	char ch;
	cin>>n>>c>>d;
	for(i=0;i<n;i++)
	{
		scanf("%d %d %c",&p,&b,&ch);//这个地方故意把p和b反过来了。。懒得改了
		node t;
		t.b=b;
		t.p=p;
		if(ch=='C')
		{
			cc[nc++]=t;//为什么不用vector。。。。。。傻了
		}
		else
		{
			dd[nd++]=t;
		}
	}
	sort(cc,cc+nc,cmp);
	sort(dd,dd+nd,cmp);
	node t;
	t.b=100005;
	t.p=0;
	cc[nc]=dd[nd]=t;
	int ans=0;
	for(i=0;i<nc;i++)
	{

		int last=c-cc[i].b;
		if(last>0)
		{
			if(last>=cc[i].b)
			{
				if(dp[0][cc[i].b]!=0)
				{
					ans=max(ans,dp[0][cc[i].b]+cc[i].p);
				}
			}
			else
			{
				if(dp[0][last]!=0)
				ans=max(ans,dp[0][last]+cc[i].p);
			}
		}
		for(j=cc[i].b;j<=cc[i+1].b;j++)
		{
			dp[0][j]=max(max(dp[0][j],dp[0][j-1]),cc[i].p);
		}
	}
//	for(i=0;i<20;i++)
//	cout<<i<<" "<<dp[0][i]<<endl;

	for(i=0;i<nd;i++)
	{

		int last=d-dd[i].b;
		if(last>0)
		{
			if(last>=dd[i].b)
			{
				if(dp[1][dd[i].b]!=0)
                ans=max(ans,dp[1][dd[i].b]+dd[i].p);
			}
			else
			{
				if(dp[1][last]!=0)
				ans=max(ans,dp[1][last]+dd[i].p);
			}
		}
		for(j=dd[i].b;j<=dd[i+1].b;j++)
		{
			dp[1][j]=max(max(dp[1][j],dp[1][j-1]),dd[i].p);
		}
	}
//	cout<<ans<<endl;
//	cout<<dp[0][c]<<" "<<dp[1][d]<<endl;
	if(ans==0&&(dp[0][c]==0||dp[1][d]==0))
	cout<<"0"<<endl;
	else
	{
	    if(dp[0][c]!=0&&dp[1][d]!=0)
		ans=max(ans,dp[0][c]+dp[1][d]);
		cout<<ans<<endl;
	}
	return 0;
 }



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值