2825: 收集金币

http://acm.zzuli.edu.cn/problem.php?id=2825

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=2e4+10;
int n,T;
int f[N][2];
int main()
{
    
    
    cin>>T;
    while(T--)
    {
    
    
        memset(f,0,sizeof f);
        cin>>n;
        int x;
        string s="LOST";
        string p;
        for(int i=1;i<=n;i++)
        {
    
    
            cin>>p>>x;
            if(p==s)
            {
    
    
                f[i][1]=max(f[i-1][0],max(f[i-1][1]-x,0));
                f[i][0]=max(0,f[i-1][0]-x);
            }
            else
            {
    
    
                f[i][1]=f[i-1][1]+x;
                f[i][0]=f[i-1][0]+x;
            }
        }
        cout<<f[n][1]<<"\n";
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/weixin_52341477/article/details/121132718