Cod sursa(job #137429)

Utilizator nod_softwareBudisteanu Ionut Alexandru nod_software Data 17 februarie 2008 12:07:51
Problema Garaj Scor 0
Compilator fpc Status done
Runda preONI 2008, Runda 4, Clasa a 10-a Marime 1.42 kb
program NOD_SOFTWARE;
type nr = record
     c,t,r,ok:integer;
end;
var fin,fout:text;
    camioane,maxi,timp,i,j,n,m,max:longint;
    v:array [1..1000000] of nr;
    duse:boolean;
{*--------------------------------*}
procedure citire;
begin
     assign(fin,'garaj.in'); reset(fin);
     assign(fout,'garaj.out'); rewrite(fout);
     readln(fin,n,m);
     for i:=1 to n do
     begin
          readln(fin,v[i].c,v[i].t);
          v[i].r:=v[i].c-v[i].t;
          v[i].ok:=0;
     end;
     close(fin);
end;
{*--------------------------------*}
procedure maxim;
begin
     duse:=false;
     while not duse do
     begin
     max:=-100;
     duse:=true;

     for i:=1 to n do
     begin
          if ((v[i].ok <= timp) and (max<=v[i].r) and (m>0)) then
          begin
               max:=v[i].r;
               maxi:=i;
               duse:=false;
          end;
     end;
          if not duse then
          begin
              m:=m-max;
              v[maxi].ok:=v[maxi].ok+2*v[maxi].t;
          end;
     end;

end;
{*---------------MAIN-------------*}
begin
     citire;
     timp:=-1;
     duse:=false;
     while m>0 do
     begin
          inc(timp);
          maxim;
     end;
     max:=-100;
     camioane:=0;
     for i:=1 to n do if max<v[i].ok then max:=v[i].ok;
     for i:=1 to n do if v[i].ok >0 then inc(camioane);
     writeln(fout,max,' ',camioane);
     close(fout);
end.