#include <iostream>
#include <vector>
using namespace std;
int main(){
int mx=-1,pos=0,len=0,p2=0,l=0,r=0,curmx=0,curlen=0;
int n,N;
cin>>n;
N=n;
while(n--){
curlen++;
int a;
cin>>a;
if(a==1)l++;
else l--;
if(l>mx){
mx=l;
pos=N-n;
}
else if(l==0){
if(curlen>len){len=curlen,p2=N-n-curlen+1;}
curlen=0;
}
}
cout<<mx<<' '<<pos<<' '<<len<<' '<<p2<<endl;
}
#include <vector>
using namespace std;
int main(){
int mx=-1,pos=0,len=0,p2=0,l=0,r=0,curmx=0,curlen=0;
int n,N;
cin>>n;
N=n;
while(n--){
curlen++;
int a;
cin>>a;
if(a==1)l++;
else l--;
if(l>mx){
mx=l;
pos=N-n;
}
else if(l==0){
if(curlen>len){len=curlen,p2=N-n-curlen+1;}
curlen=0;
}
}
cout<<mx<<' '<<pos<<' '<<len<<' '<<p2<<endl;
}
Comments
Post a Comment