Cod sursa(job #129702)

Utilizator ProtomanAndrei Purice Protoman Data 29 ianuarie 2008 21:54:45
Problema Secventa 3 Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.59 kb
var f1,f2:text;
    i,n,sc,st,m,l,u,spt,spc,x:longint;
    s,sp,mx:double;
    c,t:array[-30010..30010] of integer;
begin
        assign(f1,'secv3.in');
        reset(f1);
        assign(f2,'secv3.out');
        rewrite(f2);
        read(f1,n,l,u);
        for i:=1 to n do
                read(f1,c[i]);
        for i:=1 to n do
                read(f1,t[i]);
        for i:=1 to l-1 do
        begin
                sc:=sc+c[i];
                st:=st+t[i];
        end;
        m:=l-1;
        for i:=l to n do
        begin
                inc(m);
                sc:=sc+c[i];
                st:=st+t[i];
                s:=sc/st;
                if m>u then
                begin
                        dec(m);
                        sc:=sc-c[i-u];
                        st:=st-t[i-u];
                        s:=sc/st;
                        spc:=sc;
                        spt:=st;
                end;
                spc:=sc;
                spt:=st;
                for x:=u-1 downto l do
                begin
                        spc:=spc-c[i-x];
                        spt:=spt-t[i-x];
                        sp:=spc/spt;
                        if sp>s then
                        begin
                                m:=x;
                                sc:=spc;
                                st:=spt;
                                s:=sp;
                        end;
                end;
                if s>mx then
                        mx:=s;
        end;
        writeln(f2,mx:0:7);
        close(f1);
        close(f2);
end.