Submission #414157

#TimeUsernameProblemLanguageResultExecution timeMemory
414157shivensinha4Election (BOI18_election)C++17
28 / 100
3055 ms1780 KiB
#include <bits/stdc++.h> using namespace std; #define for_(i, s, e) for (int i = s; i < (int) e; i++) #define for__(i, s, e) for (ll i = s; i < e; i++) typedef long long ll; typedef vector<int> vi; typedef array<int, 2> ii; #define endl '\n' int main() { #ifdef mlocal freopen("test.in", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vi nums(n); for_(i, 0, n) { char c; cin >> c; nums[i] = c == 'C' ? 1 : -1; } auto solve = [&] (int l, int r) { int s = 0, mov = 0, mx = 0; for_(i, l, r+1) { s += nums[i]; if (s < 0) { mov++; s = 0; } mx = max(mx, s); } return mov+mx-s; }; int q; cin >> q; while (q--) { int l, r; cin >> l >> r; cout << solve(l-1, r-1) << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...