#include<bits/stdc++.h> using namespace std; int main() { long long int n,i,p=0,pos=0,c,j,k,len; cin>>n; long long int a[n]; for(i=0;i<n;i++) cin>>a[i]; c=0; k=0; for(i=0;i<n;i++) { if((a[i]==1)) { c=1; //nestng depth k=i; //postn for(j=i+1;j<n;j++) { k++; if(a[j]==1) c++; else break; } if(c>p) { p=c; pos=k; } } } cout<<p<<" "<<pos<<" "; k=0; p=0; c=0; for(i=0;i<n;i++) { if((a[i]==1)) { c=1; len=1; for(j=i+1;j<n;j++) { if(a[j]==1) { c++; len++; } else { c--; len++; } if(c==0) break; } if(len>p) { p=len; k=i+1; } } } cout<<p<<" "<<k; return 0; }
Asked by: Manish_Kumar_Savita on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.