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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MAXN = 1e18;
const int MAXM = 2e5;
ll N, M;
string S[MAXM+10];
ll K[MAXM+10];
ll sum=0, ans=1;
int main()
{
int i, j;
cin>>N>>M;
for(i=1; i<=M; i++) cin>>S[i]>>K[i];
for(i=M; i>=1; i--)
{
ll t=0, k=0;
for(j=S[i].size()-1; j>=0; j--)
{
if(S[i][j]=='F') t--;
else t++;
k=max(k, t);
}
ans=max(ans, max(sum+k, sum+t*(K[i]-1)+k));
sum+=K[i]*t;
}
if(sum>0) return !printf("-1\n");
printf("%lld\n", ans-1);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |