# P. Purple Rain (找子序列极点）

Purple rain falls in the magic kingdom of Linearland which is a straight, thin peninsula.

On close observation however, Professor Nelson Rogers finds that the purple rain is actually a mix of red and blue raindrops.

In his zeal, he records the location and color of the raindrops in different locations along the peninsula. Looking at the data, Professor Rogers wants to know which part of Linearland had the “least” purple rain.

After some thought, he decides to model this problem as follows. Divide the peninsula into nn  sections and number them west to east from 11to nn. Then, describe the raindrops as a sequence of RR and BB, depending on whether the rainfall in each section is primarily red or blue. Finally, find a subsequence of contiguous sections where the difference between the number of RR and the number of BB is maximized.

1 Input

The input consists of a single line containing a string of nn characters (1 ≤ n ≤ 10^{5} )(1≤n≤105), describing the color of the raindrops in sections 11 to nn.

It is guaranteed that the string consists of uppercase ASCIIASCII letters ‘RR’ and ‘BB’ only.

2 Output

Print, on a single line, two space-separated integers that describe the starting and ending positions of the part of Linearland that had the least purple rain. These two numbers should describe an inclusive range; both numbers you print describe sections included in the range.

If there are multiple possible answers, print the one that has the westernmost starting section. If there are multiple answers with the same westernmost starting section, print the one with the westernmost ending section.

BBRRBRRBRB

3 7

BBRBBRRB

1 5

(就是找最大点和最小点，排序，完事)

# include <iostream>
# include <algorithm>
# include <cstring>
# include <math.h>
# include <stdio.h>
# include <vector>
# include <map>
using namespace std;
# define ll long long
# define ull unsigned long long
char a[100100];
int pre[100100];
int main(){

scanf("%s",a+1);
int len = strlen(a+1);
memset(pre,0,sizeof(pre));
for(int i = 1; i <= len; i++){
if(a[i] == 'B'){
pre[i]++;
}
else{
pre[i]--;
}
}
int l = 0,r = 0;
int max1 = -100100;
int min1 = 100100;
pre[0] = 0;
max1 = max(pre[0],max1);
min1 = min(pre[0],min1);

for(int i = 1; i <= len; i++){
pre[i] = pre[i-1]+pre[i];
if(max1 < pre[i]){
max1 = pre[i];
r = i;
}
if(min1 > pre[i]){
min1 = pre[i];
l = i;
}
//cout << max1 << " " << min1 << endl;
}
int l1 = min(l,r);
int r1 = max(l,r);
printf("%d %d\n",l1+1,r1);

return  0;





04-05 178

09-17 1473
05-22 123
09-06 73
08-21 5880
12-17 119
05-24 1万+