Cod sursa(job #213935)

Utilizator FllorynMitu Florin Danut Flloryn Data 12 octombrie 2008 08:38:29
Problema Secventa 3 Scor 40
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.36 kb
program pascal;
var f,g:text;
    pi,ps,i,j,n,k,u:longint;
    max:real;
    sumac,sumat:int64;
    cost,timp:array[1..30000] of longint;
begin
assign(f,'secv3.in'); reset(f);
assign(g,'secv3.out'); rewrite(g);
readln(f,n,k,u);
for i:=1 to n do read(f,cost[i]);
readln(f);
for i:=1 to n do read(f,timp[i]);

max:=-2000000000;
for i:=1 to n-k+1 do
  begin
    sumac:=0;
    sumat:=0;
    for j:=i to i+k-1 do
      begin
          sumac:=sumac+cost[j];
          sumat:=sumat+timp[j];
      end;
    if sumac/sumat>max then max:=sumac/sumat;

    for j:=i+k to i+u-1 do
    if j<=n then
     begin
        sumac:=sumac+cost[j];
        sumat:=sumat+timp[j];
        if sumac/sumat>max then  max:=sumac/sumat;
     end;
   end;

{sumac:=0;
sumat:=0;
for i:=1 to n do
  begin
    sumac:=sumac+cost[i];
    sumat:=sumat+timp[i];
    if (i>=k) and (sumac/sumat>max) then
                begin
                  max:=sumac/sumat;
                  ps:=i;
                end;
   end;

max:=-2000000000;
sumac:=0;
sumat:=0;
i:=ps;
for j:=1 to u do
  begin
     sumac:=sumac+cost[i];
     sumat:=sumat+timp[i];
     if (j>=k) and (sumac/sumat>max) then
                   begin
                    max:=sumac/sumat;
                    pi:=i;
                   end;
     i:=i-1;
  end;}

write(g,max:0:2);
close(f);
close(g);
end.