问用已拥有的货币你买两个喷泉,最大漂亮值多少
必须要买两个,买不起两个就是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;
}