Pagini recente » Cod sursa (job #1975279) | Cod sursa (job #2759727) | Cod sursa (job #3167511) | Cod sursa (job #1600402) | Cod sursa (job #2771971)
#include <fstream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <bitset>
#define pb(a) push_back(a)
using namespace std;
ifstream cin("secv.in");
ofstream cout("secv.out");
const int nmax = 5e3;
int v[nmax + 1], aux[nmax + 1], ind[nmax + 1];
int n, p = 1;
int main(){
cin >> n;
for(int i = 1; i <= n; ++i){
cin >> v[i];
aux[i] = v[i];
}
sort(aux + 1, aux + n + 1);
for(int i = 1; i <= n; ++i){
if(aux[i] != aux[i + 1]){
ind[p] = aux[i];
p++;
}
}
p--;
int k = 1, st = 0, dr = 0;
bool gasit1 = false, gasit2 = false;
for(int i = 1; i <= n; ++i){
if(v[i] == ind[k]){
if(k == 1){
st = i;
}
if(k == p){
dr = i;
}
k++;
}
}
if(dr != 0){
cout << dr - st + 1;
}
else{
cout << -1;
}
return 0;
}