Pagini recente » Cod sursa (job #731821) | Cod sursa (job #2161373) | Cod sursa (job #1707154) | Cod sursa (job #1840553) | Cod sursa (job #180982)
Cod sursa(job #180982)
#include<stdio.h>
#include<stdlib.h>
#define N 10000
int v[5000],w[5000],n,i,j,q;
int comp(const void *a,const void *b){
return *(int *)a-*(int *)b;
}
int cauta(int x){
for(int i=0;i<q;++i)
if(w[i]==x)
return 0;
return 1;
}
int main () {
freopen("secv.in","r",stdin);
freopen("secv.out","w",stdout);
int x,k,min=N;
scanf("%d",&n);
for(i=0;i<n;++i){
scanf("%d",&v[i]);
if(cauta(v[i]))
w[q++]=v[i];
}
qsort(w,q,sizeof(int),comp);
for(i=0;i<n;++i)
if(v[i]==w[0]){
x=1;
k=i;
for(j=i+1;j<n;++j)
if(v[j]==w[x]){
++x;
k=j;
}
if(v[k]==w[q-1])
if(k-i+1<min)
min=k-i+1;
}
if(min==N)
printf("-1\n");
else
printf("%d\n",min);
return 0;
}