Pagini recente » Cod sursa (job #408301) | Cod sursa (job #1065838) | Cod sursa (job #2475137) | Cod sursa (job #2129709) | Cod sursa (job #764601)
Cod sursa(job #764601)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
#define nmax 5005
ifstream f("secv.in");
ofstream g("secv.out");
int temp[nmax], a[nmax], rez[nmax];
int n;
void citeste(){
f >> n;
for(int i=1; i<=n; i++) f >> temp[i], a[i] = temp[i];
sort(temp+1, temp+n+1 );
}
void rezolva(){
for(int i=1; i<=n; i++){
if (temp[i] == temp[i-1]) continue;
rez[++rez[0]] = temp[i];
}
int j = 1;
int sol = (1<<29);
for(int i=1; i<=n; i++){
if (a[i] == rez[1]){
int j = 2;
for(int k=i+1; k<=n && j<=rez[0]; k++){
if (a[k] == rez[j]){
if (j == rez[0]){
if (k-i+1 < sol) sol = k-i+1;
break;
}
j++;
}
}
}
}
g << sol << "\n";
}
int main(){
citeste();
rezolva();
f.close();
g.close();
return 0;
}