This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fs first
#define sc second
ll N,M;
vector<pair<string,ll>> v;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>N>>M;
ll sum = 0,ans = 0;
for(ll i = 0;i<M;i++){
string s;
ll t;
cin>>s>>t;
reverse(s.begin(),s.end());
v.push_back(make_pair(s,t));
}
reverse(v.begin(),v.end());
for(auto [s,t] : v){
ll ts = 0,tbig = -1e18;
for(auto &i:s){
if(i == 'F'){
ts--;
tbig = max(tbig,ts);
}
else ts++;
}
ans = max(ans,sum+tbig);
sum += ts*(t-1);
ans = max(ans,sum+tbig);
sum += ts;
}
if(sum>0)cout<<"-1\n";
else cout<<ans<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |