Pagini recente » Cod sursa (job #2789190) | Cod sursa (job #1975589) | Cod sursa (job #2905434) | Rating Pirlogea Luciana-Elena (LucianaElena) | Cod sursa (job #572886)
Cod sursa(job #572886)
var e, c:array [1..1001] of longint;
et, ct:array [0..501501] of longint;
i, j, m, n, t, min, aux, k, r:longint;
ok:boolean;
f, g:text;
procedure qsort (st, dr:longint);
var s, d, p:longint;
begin
if dr-st>=1 then
begin
s:=st; d:=dr;
p:= e[random (dr-st)+st];
while s< d do
begin
while e[s]<p do s:=s+1;
while e[d]>p do d:=d-1;
if s<=d then
begin
aux:=e[s]; e[s]:=e[d]; e[d]:=aux;
aux:=c[s]; c[s]:=c[d]; c[d]:=aux;
s:=s+1; d:=d-1;
end;
end;
if st<d then qsort (st, d);
if s<dr then qsort (s, dr);
end;
end;
begin
assign (f, 'energii.in'); reset (F);
assign (g, 'energii.out'); rewrite (g);
readln (f, n);
readln (f, t);
for i := 1 to n do
begin
read (f, e[i], c[i]);
end;
qsort (1, n);
k:=0; min:=maxlongint;
for i := 1 to n do
begin
for j := 0 to i-1 do
begin
if et[j]+e[i] < t then
begin
k:=k+1;
ct[k]:=ct[j]+c[i];
et[k]:=et[j]+e[i];
end
else
begin
if ct[j]+c[i] < min then min := ct[j]+c[i];
end;
end;
end;
writeln (g, min);
close (f); close (g);
end.