题目链接
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
const int N=1e7+10;
int n,a,b,red[N],yellow[N],white[N];
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>a>>b;
for(int i=1;i<=n;i++){
int x;
cin>>x;
red[i]=red[i-1]+(x==1);
yellow[i]=yellow[i-1]+(x==2);
white[i]=white[i-1]+(x==0);
}
int l=1,r=n;
while(red[r]-red[l]>=a&&yellow[r]-yellow[l]>=b) l++;
while(red[r-1]>=a-red[l-1]&&yellow[r-1]-yellow[l-1]>=b) r--;
cout<<white[r]-white[l-1]<<endl;
return 0;
}
思路是双指针来找到最小的满足条件的区间