Pagini recente » Cod sursa (job #2126922) | Cod sursa (job #3159859) | Cod sursa (job #996510) | Cod sursa (job #2441585) | Cod sursa (job #514282)
Cod sursa(job #514282)
const f='energiii.in';h='energiii.out';
var
n,w,i,j,min,s:longint;
c,e:array[1..1001] of longint;
g:array[1..10005] of longint;
begin
assign(input,f);reset(input);
assign(output,h);rewrite(output);
for i:=1 to n do readln(e[i],c[i]);
for i:=1 to 2*w do g[i]:=100000000;
for i:=1 to n do
for j:=2*w downto 1 do
if j>=e[i] then
if g[j-e[i]]+c[i]<g[j] then g[j]:=g[j-e[i]]+c[i];
min:=100000000;
for i:=2 to w*2 do
if min>g[i] then min:=g[i];
if min=100000000 then write('-1')
else write(min);
close(input);close(output);
end.