Cod sursa(job #514282)

Utilizator vendettaSalajan Razvan vendetta Data 18 decembrie 2010 12:41:21
Problema Energii Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.64 kb
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.