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;
char S[200005];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
long long N; int M; cin >> N >> M;
long long y = 0, mny = 0;
for (int i = 0; i < M; ++i) {
long long K, sum = 0, mnSum = 0;
cin >> S + 1 >> K;
for (int i = 1, t = 0; S[i]; ++i) {
t++;
if (S[i] != S[i + 1]) {
sum += S[i] == 'M' ? t : -t;
mnSum = min(mnSum, sum);
t = 0;
}
}
mny = min({mny, y + sum * (K - 1) + mnSum, y + mnSum});
y += K * sum;
}
if (y > 0) printf("-1");
else printf("%lld", max(0ll, y -mny - 1));
return 0;
}
Compilation message (stderr)
toilets.cpp: In function 'int main()':
toilets.cpp:12:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
cin >> S + 1 >> K;
~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |