Cod sursa(job #29722)

Utilizator ProtomanAndrei Purice Protoman Data 9 martie 2007 20:35:20
Problema Secventa 2 Scor 90
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.93 kb
var a,b:array[1..50000] of Integer; SM,SC,ince,sf,poz,i,n,min,nr,j,k:longint; f1,f2:text;
Begin
        assign(f1,'secv2.in');
        reset(f1);
        assign(f2,'secv2.out');
        rewrite(f2);
        read(f1,n,k);
        for i:=1 to n do read(f1,a[i]);
        SM:=a[1];
        SC:=SM;
        poz:=1;
        ince:=1;
        sf:=1;
        min:=-maxint;
        for i:=2 to n do
        begin
                if SC<0 then
                begin
                        SC:=a[i];
                        poz:=i
                end
                else SC:=SC+a[i];
                if i-poz+1>k then if Sm<SC then
                begin
                        SM:=SC;
                        ince:=poz;
                        sf:=i;
                end;
        end;
        for j:=ince to sf do b[j]:=1;
        nr:=nr-(sf-ince+1);
        write(f2,POZ,' ',SF,' ',sm);
        close(f1);
        close(f2);
End.