Cod sursa(job #812446)

Utilizator R.A.RFMI Romila Remus Arthur R.A.R Data 13 noiembrie 2012 21:21:03
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <fstream>
#define NMAX 500002
using namespace std;

ifstream in("secventa.in");
ofstream out("secventa.out");

int Deque[NMAX],S,F = -1;
int V[NMAX],N,K;

int main()
{
    int i,Baza = -NMAX,Start;
    in>>N>>K;
    for(i=1;i<=N;i++)
    {
        in>>V[i];
        while(i - Deque[S] >=K)
            S++;
        while(F>=S&&V[i]<=V[Deque[F]])
            --F;
        Deque[++F] = i;
        if(i>=K&&V[Deque[S]]>Baza)
            Baza = V[Deque[S]], Start = Deque[S];
    }
    out<<Start<<' '<<Start+K-1<<' '<<Baza<<'\n';
    return 0;
}