Submission #258514

#TimeUsernameProblemLanguageResultExecution timeMemory
258514arnold518Toilets (JOI16_toilets)C++14
100 / 100
113 ms9100 KiB
#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) cout<<"-1\n"; else cout<<ans-1<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...