Pagini recente » Cod sursa (job #3269677) | Cod sursa (job #1970078) | Cod sursa (job #2498329) | Cod sursa (job #965959) | Cod sursa (job #1370803)
type sir = array[1..5001] of longint;
var a,a1:sir;
g,w:longint;
f:text;
procedure cit(var g,w:longint);
var t,k,i,j:longint;
begin
assign(f,'energii.in'); reset(f);
readln(f,g); readln(f,w);
for k:=1 to g do begin
readln(f,i,j);
a1:=a;
for t:=1 to w do
if (a[t] <> 0) then
if (a[t+i] = 0) then a1[t+i]:=a[t]+j
else if (a[t+i] > a[t]+j) then a1[t+i]:=a[t]+j;
if (a[i] = 0) then a1[i]:=j
else if (j < a[i]) then a1[i]:=j;
a:=a1;
end;
close(f);
end;
procedure tip;
var i:longint;
begin
assign(f,'energii.out'); rewrite(f); i := w;
while ((a[i] = 0) and (i <= 5001)) do inc(i);
if (i < 5001) then write(f,a[i])
else write(f,-1);
close(f);
end;
begin {pp}
cit(g,w);
tip;
end.