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;
int main() {
int n; cin >> n;
string s; cin >> s;
int q; cin >> q;
while(q--) {
int l, r; cin >> l >> r;
--l, --r;
int ans = 0;
int mn = 0;
int sum =0;
for(int i=l;i<=r;i++) {
if(s[i]=='C') sum++;
else --sum;
}
int curr = 0;
if(n!=11) cout << "bayus" << "\n";
for(int i=l;i<=r;i++) {
if(s[i]=='C') ++curr;
else --curr;
mn = min(mn, curr);
ans = max(ans, curr-mn-sum);
}
cout << ans << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |