Cod sursa(job #48526)

Utilizator cezar305Mr. Noname cezar305 Data 4 aprilie 2007 21:11:04
Problema Secventa 2 Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.91 kb
var a,b:array[1..50000] of Integer; SM,SC,ince,sf,poz,i,n,j,k,s: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 begin read(f1,a[i]); s:=s+a[i]; end;
        SM:=a[1];
        SC:=SM;
        poz:=1;
        ince:=1;
        sf:=1;
        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;
        if n=k then begin sf:=n; sm:=s; end;
        write(f2,ince,' ',SF,' ',sm);
        close(f1);
        close(f2);
End.