Pagini recente » Cod sursa (job #1977848) | Cod sursa (job #1631753) | Cod sursa (job #1238047) | Cod sursa (job #1793250) | Cod sursa (job #137429)
Cod sursa(job #137429)
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.