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;
#define int int64_t
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
int f(vector<int> v) {
int ans = 0;
int s = 0;
for(int i=0;i<sz(v);i++) {
s += v[i];
if(s < 0) {
v[i] = s = 0;
ans++;
}
}
return ans;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> v(n);
for(int i=0;i<n;i++) {
char c;
cin >> c;
if(c=='C') v[i] = 1;
else v[i] = -1;
}
int q;
cin >> q;
while(q--) {
int l, r;
cin >> l >> r;
vector<int> Q;
for(int i=l-1;i<r;i++) {
Q.pb(v[i]);
}
int ans = f(Q);
reverse(all(Q));
ans = max(ans, f(Q));
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... |