Pagini recente » Cod sursa (job #1338985) | Cod sursa (job #3266082) | Cod sursa (job #990928) | Cod sursa (job #417233) | Cod sursa (job #742121)
Cod sursa(job #742121)
Program p1;
const limit=100000000;
var fi,fo :text;
i,g,j,w : longint;
c: array[-2..1009,-2..5009] of longint;
eg,cost : array[-2..1009] of integer;
Function min(a,b : longint):longint;
begin
if a<b then min:=a
else min:=b;
end;
begin
assign(fi,'energii.in'); reset(fi);
assign(fo,'energii.out'); rewrite(fo);
readln(fi,g); readln(fi,w);
for i:=1 to g do readln(fi,eg[i],cost[i]);
for i:=0 to g do
for j:=0 to w do c[i,j]:=limit;
for i:=1 to g do
for j:=1 to w do if eg[i]<j then c[i,j]:=min(c[i-1,j],c[i-1,j-eg[i]]+cost[i])
else c[i,j]:=min(c[i-1,j],cost[i]);
if c[g,w]=limit then write(fo,'-1')
else write(fo,c[g,w]);
close(fi); close(fo);
end.