显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int species[100010],area[100010];
int n,fg,fh,gmax,hmax,ans=0;
int main(){
freopen("leaders.in","r",stdin);
freopen("leaders.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
char c;
for(int i=1;i<=n;i++){
cin>>c;
if(c=='G'){
species[i]=1;
gmax=i;
}
else{
species[i]=2;
hmax=i;
}
}
for(int i=1;i<=n;i++){
cin>>area[i];
}
for(int i=1;i<=n;i++){
if(species[i]==2){
continue;
}
if(area[i]>=gmax){
fg=i;
}
break;
}
for(int i=1;i<=n;i++){
if(species[i]==1){
continue;
}
if(area[i]>=hmax){
fh=i;
}
break;
}
for(int i=1;i<=n;i++){
if((fg&&species[i]==2&&i<fg&&area[i]>=fg)||(fh&&species[i]==1&&i<fh&&area[i]>=fh)){
ans++;
}
}
if(fg&&fh&&area[min(fg,fh)]<max(fg,fh)){
ans++;
}
cout<<ans<<endl;
return 0;
}