Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- typedef long long ll;
- int main()
- {
- ll n,i;
- int c1=0,c2=0,count=0,ad=-999999999,switc=-1,a1=-999999999,a2=-999999999;
- cin>>n;
- vector<ll>a(n);
- for(i=0;i<n;i++)
- {
- cin>>a[i];
- }
- for(i=0;i<n;)
- {
- do
- {
- if(a[i]==1)
- {
- c1++;
- if((switc==1)||(switc==-1))
- {
- count++;
- switc=0;
- }
- }
- else if(a[i]==2)
- {
- c1--;
- }
- else if(a[i]==3)
- {
- c2++;
- if((switc==0)||(switc==-1))
- {
- count++;
- switc=1;
- }
- }
- else
- {
- c2--;
- }
- i++;
- } while ((c1!=0)||(c2!=0));
- //cout<<count<<endl;
- ad=max(ad,count);
- count=0;
- switc=-1;
- }
- count=0;
- for(i=0;i<n;)
- {
- count=0;
- do
- {
- if(a[i]==1)
- {
- c1++;
- }
- else if(a[i]==2)
- {
- c1--;
- }
- i++;
- count++;
- } while (c1!=0);
- a1=max(a1,count);
- }
- count=0;
- for(i=0;i<n;)
- {
- count=0;
- do
- {
- if(a[i]==3)
- {
- c2++;
- }
- else if(a[i]==4)
- {
- c2--;
- }
- i++;
- count++;
- } while (c2!=0);
- a2=max(a2,count);
- }
- cout<<ad<<" "<<a1<<" "<<a2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement