#include<cstdio>
#include<iostream>
#include<queue>
using namespace std;
const int N=2e5+5;
struct D {
int x,y,z;
bool operator <(const D&a) const {
if(z!=a.z) return z>a.z;
return x>a.x;
}
} e;
priority_queue <D> q;//按照差值从小到大排序
char s[N];
int l[N],r[N],a[N],c[N][2],ans;
int n;
bool v[N];
int abs(int a) {
return a>0?a:-a;
}
int main() {
// freopen("dancinglessons.in","r",stdin);
// freopen("dancinglessons.out","w",stdout);
scanf("%d",&n);
getchar();
for(int i=1; i<=n; i++) s[i]=getchar();
for(int i=1; i<=n; i++) scanf("%d",&a[i]);
for(int i=1; i<n; i++) r[i]=i+1;
for(int i=1; i<=n; i++) l[i]=i-1;
for(int i=2; i<=n; i++) if((s[i]=='B'&&s[i-1]=='G')||(s[i]=='G'&&s[i-1]=='B')) {
e.x=i-1;
e.y=i;
e.z=abs(a[i]-a[i-1]);
q.push(e);
}
while(q.size()) {
e=q.top();
q.pop();
while(q.size()&&(v[e.x]||v[e.y])) {
e=q.top();
q.pop();
}
if(v[e.x]||v[e.y]) break;
v[e.x]=1;
v[e.y]=1;
ans++;
c[ans][0]=e.x;
c[ans][1]=e.y;
r[l[e.x]]=r[e.y];
l[r[e.y]]=l[e.x];
if(s[l[e.x]]!=s[r[e.y]]&&l[e.x]!=0&&r[e.y]!=0) {
e.x=l[e.x];
e.y=r[e.y];
e.z=abs(a[e.x]-a[e.y]);
q.push(e);
}
}
printf("%d\n",ans);
for(int i=1; i<=ans; i++) printf("%d %d\n",c[i][0],c[i][1]);
return 0;
}
我在机房测试A掉了,结果洛谷一测就爆零了,求助,QWQ