Pagini recente » Cod sursa (job #1856800) | Cod sursa (job #1873474) | Cod sursa (job #2664776) | Cod sursa (job #1923881) | Cod sursa (job #186377)
Cod sursa(job #186377)
program energiii;
type vector=array[1..1001]of integer;
type energii=record
c,e:vector;
end;
var e,c:vector;
f,g:text;
a,b:energii;
n,w,i,j,k,min:longint;
procedure calculare(i:longint);
var j,k:longint;
begin
b.e[i]:=e[i];
b.c[i]:=c[i];
if b.e[i]>=w then
if b.c[i]<min then
min:=b.c[i];
for j:=i+1 to n do
begin
b.e[j]:=a.e[j]-a.e[j-1]+b.e[j-1];
b.c[j]:=a.c[j]-a.c[j-1]+b.c[j-1];
if b.e[j]>=w then
if b.c[j]<min then
min:=b.c[j];
end;
a.e:=b.e;
a.c:=b.c;
if i<n then
calculare(i+1);
end;
begin
assign(f,'energii.in');
reset(f);
readln(f,n);
readln(f,w);
for i:=1 to n do
readln(f,e[i],c[i]);
close(f);
min:=maxlongint;
for j:=1 to n do
begin
for k:=1 to j do
begin
a.e[j]:=a.e[j]+e[k];
a.c[j]:=a.c[j]+c[k];
end;
if a.e[j]>=w then
if a.c[j]<min then
min:=a.c[j];
end;
calculare(2);
assign(g,'energii.out');
rewrite(g);
if min<>maxlongint then
write(g,min) else
write(g,'-1');
close(g);
end.