Cod sursa(job #3240936)

Utilizator mihaigeorgescuGeorgescu Mihai mihaigeorgescu Data 24 august 2024 15:15:20
Problema Secv Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <fstream>
#include <map>
using namespace std;
ifstream fcin("secv.in");
ofstream fout("secv.out");
int n,v[10001],st,dr,ok,maxx;
map < int , int > m;
int main()
{
    fcin>>n;
    for(int i=1; i<=n; i++)
    {
        fcin>>v[i];
        m[v[i]]=1;
        maxx=max(maxx,v[i]);
    }
    int last=1;
    for(auto & i : m)
    {
        for(int j=last; j<=n; j++)
        {
            if(v[j]==i.first)
            {
                if(ok==0)
                    st=j,ok=1;
                dr=j;
                last=j+1;
                i.second=2;
                break;
            }
        }
    }
    if(m[maxx]!=2)
        fout<<-1;
    else
        fout<<dr-st+1;
    return 0;
}