Cod sursa(job #48651)

Utilizator Bluedrop_demonPandia Gheorghe Bluedrop_demon Data 4 aprilie 2007 23:01:46
Problema Secventa Scor 80
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.25 kb
{
    Program secventa
}

Program secv;

Var n, k, i, q, pr, ul : Longint;
    nr : array[0..500000] of integer;
    poz : array[1..500000] of 1..500000;
    el, max : integer;

Begin
    Assign( input, 'secventa.in' );
    Reset( input );
        Readln( n, k );
        pr := 1;
        ul := 1;
        nr[0] := -MaxInt;
        max := -MaxInt;
        q := 1;
        For i := 1 to k-1 do
            Begin
                Read( el );
                While ( ul > pr-1 ) and ( el < nr[ul] ) do ul := ul-1;
                ul := ul+1;
                nr[ul] := el;
                poz[ul] := i;
            End;
        For i := k to n do
            Begin
                Read( el );
                While ( ul > pr-1 ) and ( el < nr[ul] ) do ul := ul-1;
                ul := ul+1;
                nr[ul] := el;
                poz[ul] := i;
                if i - poz[pr] >= k then pr := pr+1;
                if nr[pr] > max then
                    Begin
                        q := i-k+1;
                        max := nr[pr];
                    End;
            End;
    Close( input );

    Assign( output, 'secventa.out' );
    Rewrite( output );
        Writeln( q, ' ', q+k-1, ' ', max );
    Close( output );
End.