Pagini recente » Cod sursa (job #798176) | Cod sursa (job #820715) | Cod sursa (job #2428630) | Cod sursa (job #159306) | Cod sursa (job #1370949)
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,max:longint;
begin
assign(f,'energii.in'); reset(f);
readln(f,g); readln(f,w); max:=maxlongint;
for k:=1 to g do begin
readln(f,i,j);
a1:=a;
for t:=1 to 3000 do
if (a[t] <> 0) then
if (a[t+i] = 0) then begin
a1[t+i]:=a[t]+j;
if ((a1[t+i] > w) and (max > a1[t+i])) then max:=a1[t+i];
end
else if (a[t+i] > a[t]+j) then begin
a1[t+i]:=a[t]+j;
if ((a1[t+i] > w) and (max > a1[t+i])) then max:=a1[t+i];
end;
if (a[i] = 0) then begin
a1[i]:=j;
if ((a1[i] > w) and (max > a1[i])) then max:=a1[i];
end
else if (j < a[i]) then begin
a1[i]:=j;
if ((a1[i] > w) and (max > a1[i])) then max:=a1[i];
end;
a:=a1;
end;
close(f); assign(f,'energii.out'); rewrite(f); if (max <> maxlongint) then write(f,max) else write(f,-1); close(f);
end;
begin {pp}
cit(g,w);
end.