Pagini recente » Cod sursa (job #3242558) | Cod sursa (job #1545215) | Cod sursa (job #1141581) | Cod sursa (job #1124231) | Cod sursa (job #300910)
Cod sursa(job #300910)
var sol:array[0..10000] of longint;
en,cost:array[1..5000] of integer;
nrg,w:integer;
rez:longint;
procedure citire;
var f:text;
i:integer;
begin
assign(f,'energii.in'); reset(f);
readln(f,nrg);
readln(f,w);
for i:=1 to nrg do readln(f,en[i],cost[i]);
close(f);
end;
procedure rezolvare;
var i,j,max:longint;
begin
sol[0]:=0;
max:=0;
for i:=1 to nrg do
for j:=max downto 0 do
if sol[j+en[i]]<sol[j]+cost[i] then
begin
sol[j+en[i]]:=sol[j]+cost[i];
if j+en[i]>max then max:=j+en[i];
end;
rez:=maxlongint;
for i:=0 to max do
if (sol[i]<rez) and (sol[i]>=w) then rez:=sol[i];
end;
procedure afisare;
var g:text;
begin
assign(g,'energii.out'); rewrite(g);
if rez<>maxlongint then writeln(g,rez)
else writeln(g,-1);
close(g);
end;
begin
citire;
rezolvare;
afisare;
end.