Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void remp(int t[],int n)
- {
- for (int a=0;a<n;a++)
- {
- scanf("%d",t+a);
- }
- }
- int distinct(int t[],int a,int b)
- {
- for (int x=a;x<b;x++)
- {
- if (t[x]==t[b])
- {
- a=x;
- break;
- }
- }
- return t[a]!=t[b];
- }
- int GetSubarray(int t[],int n)
- {
- int max=0,sum=1;
- for (int a=0;a<n;a++)
- {
- for (int b=a+1;b<n;b++)
- {
- if(!distinct(t,a,b))
- break;
- sum++;
- }
- if (sum>max)
- max=sum;
- if (max>=n-a)
- break;
- sum=1;
- }
- return max;
- }
- int main()
- {
- int n;
- scanf("%d",&n);
- int t[n];
- remp(t,n);
- printf("\n\n%d\n",GetSubarray(t,n));
- }
- /*
- 8
- 5
- 1
- 3
- 5
- 2
- 3
- 4
- 1
- *//*
- 11
- 1
- 2
- 3
- 4
- 1
- 9
- 8
- 7
- 1
- 5
- 2
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement