Submission #991369

#TimeUsernameProblemLanguageResultExecution timeMemory
991369gmroh06Toilets (JOI16_toilets)C++17
36 / 100
21 ms5980 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; inline void fastio() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); } ll n, m, ans, sum; stack<pair<string, ll>> s; int main() { fastio(); cin >> n >> m; while (m--) { string str; ll t; cin >> str >> t; s.emplace(str, t); } while (!s.empty()) { auto [str, k] = s.top(); s.pop(); ll mx = 0, tmp = 0; for (auto it = str.end() - 1; it >= str.begin(); it--) { tmp += *it == 'M' ? 1 : -1; mx = max(mx, tmp - 1); } ans = max(ans, sum + k * mx); sum += tmp; } cout << (sum <= 0 ? ans : -1); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...