Submission #696779

#TimeUsernameProblemLanguageResultExecution timeMemory
696779Cross_RatioToilets (JOI16_toilets)C++14
100 / 100
27 ms5424 KiB
#include <bits/stdc++.h> #define int long long using namespace std; string s[100005]; int A[100005]; signed main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); int N; int M; cin >> N >> M; int i, j; for(i=0;i<M;i++) cin >> s[i] >> A[i]; int ma = 0; int sum = 0; for(i=M-1;i>=0;i--) { int cnt = 0; int ma2 = 0; for(j=s[i].length()-1;j>=0;j--) { if(s[i][j]=='M') cnt++; else cnt--; ma2 = max(ma2, cnt); } if(cnt<=0) ma = max(ma, sum + ma2); else ma = max(ma, sum + ma2 + (A[i]-1) * cnt); sum += cnt * A[i]; } cout << (sum <= 0 ? max(0LL,ma-1) : -1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...