Cod sursa(job #129655)

Utilizator ProtomanAndrei Purice Protoman Data 29 ianuarie 2008 20:49:35
Problema Secventa 3 Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 2 kb
var f1,f2:text;
    i,n,sc,st,m,l,u,spt,spc,x:longint;
    s,sp,mx:double;
    c,t:array[0..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 s>mx then
                        mx:=s;
                if m>u then
                begin
                        sc:=sc-c[i-u];
                        st:=st-t[i-u];
                        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;
                                end;
                        end;
                end;
                if m<>l then
                        while (sc-c[i-m+1])/(st-t[i-m+1])>s do
                        begin
                                sc:=sc-c[i-m+1];
                                st:=st-t[i-m+1];
                                s:=sc/st;
                                dec(m);
                                if m=l then
                                        break;
                        end;
                if s>mx then
                        mx:=s;
        end;
        writeln(f2,mx:0:7);
        close(f1);
        close(f2);
end.