看见讨论群的大佬说这题没有黄题难度,可是本蒟蒻只能拿50pts,求大佬指点
#include <iostream>
using namespace std;
const int maxn=1e6+10;
int t,n,x,y;
int a[maxn],b[maxn];
int main(){
scanf("%d",&t);
while(t--){
scanf("%d",&n);
x=0,y=1;
a[0]=b[0]=a[n+1]=b[n+1]=0;
for(int i=1; i<=n; i++) scanf("%d%d",&a[i],&b[i]);
while(true){
if((!x&&y==-1) or (y==1&&x==n+1)) break;
if(y==1){
x++;
if(a[x]>0) y=-1;
a[x]--;
}
else if(y==-1){
x--;
if(b[x]>0) y=1;
b[x]--;
}
}
printf("%d\n",x);
}
return 0;
}