首A
2024-06-30 09:14:55
发布于:浙江
#include <bits/stdc++.h>
using namespace std;
int n;
string opt;
int x,y;
int s1[1000],s2[1000];
int e1[1000],e2[1000];
struct cz{
string mtd;
int up,dn;
};
int cnt=0;
cz m[1000];
int main(){
cin>>n;
s2[0]=INT_MAX-1000;
for (int i = 1;i<=n;i++){
cin>>opt>>x>>y;
if (opt=="off"){
m[n-cnt]={"off",x,y};
cnt++;
s1[i]=max(0,s1[i-1]-y);
s2[i]=max(0,s2[i-1]-x);
}
else if(opt=="none"){
m[n-cnt]={"none",x,y};
cnt++;
s1[i]=max(x,s1[i-1]);
s2[i]=min(y,s2[i-1]);
}
else{
m[n-cnt]={"on",x,y};
cnt++;
s1[i]=s1[i-1]+x,s2[i]=s2[i-1]+y;
}
}
int ans1=s1[n],ans2=s2[n];
s1[1]=s1[n],s2[1]=s2[n];
for (int i = 1;i<=n;i++){
x=m[i].up,y=m[i].dn,opt=m[i].mtd;
if (opt=="on"){
s1[i]=max(0,s1[i-1]-y);
s2[i]=max(0,s2[i-1]-x);
}
else if(opt=="none"){
s1[i]=max(x,s1[i-1]);
s2[i]=min(y,s2[i-1]);
}
else{
s1[i]=s1[i-1]+x,s2[i]=s2[i-1]+y;
}
}
cout<<s1[n]<<" "<<s2[n]<<endl;
cout<<ans1<<" "<<ans2<<endl;
return 0;
}
这里空空如也
有帮助,赞一个