Pagini recente » Cod sursa (job #2391976) | Cod sursa (job #226696) | Cod sursa (job #3252403) | Cod sursa (job #1422159) | Cod sursa (job #514283)
Cod sursa(job #514283)
const f='energii.in';h='energii.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.