Cod sursa(job #129636)

Utilizator ProtomanAndrei Purice Protoman Data 29 ianuarie 2008 20:28:40
Problema Secventa 3 Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.9 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;
                while (sc-c[i-m])/(st-t[i-m])>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 m>u then
                begin
                        sc:=sc-c[i-u];
                        st:=st-t[i-u];
                        spc:=sc;
                        spt:=st;
                        for x:=u-1 downto l-1 do
                        begin
                                spc:=spc-c[i-x];
                                spt:=spt-t[i-x];
                                sp:=sc/st;
                                if sp>s then
                                begin
                                        m:=x+1;
                                        sc:=spc;
                                        st:=spt;
                                end;
                        end;
                end;
                if s>mx then
                        mx:=s;
        end;
        writeln(f2,mx:0:7);
        close(f1);
        close(f2);
end.