# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
60919 | ksun48 | Homecoming (BOI18_homecoming) | C++14 | 0 ms | 0 KiB |
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;
typedef long long LL;
int n;
int q;
string s;
vector<int> psums;
int max_psum(int a, int b){
int z = 0;
for(int i = a; i <= b; i++){
for(int j = i; j <= b; j++){
z = max(psums[j] - psums[i], z);
}
}
return z;
}
int main(){
cin.sync_with_stdio(0); cin.tie(0);
cin >> n >> s >> q;
psums.push_back(0);
for(int i = 0; i < s.size(); i++){
if(s[i] == 'C'){
psums.push_back(psums[psums.size() - 1] + 1);
} else {
psums.push_back(psums[psums.size() - 1] - 1);
}
}
for(int i = 0; i < q; i++){
int l, r;
cin >> l >> r;
l--; r--;
r++;
int a = max_psum(l, r);
cout << a - (psums[r] - psums[l]) << '\n';
}
}