Pagini recente » Cod sursa (job #949524) | Cod sursa (job #264727)
Cod sursa(job #264727)
var u,ala,s,cs,min,a,b,t,aux,aux2,i,w,c,g:integer; m,n:real;
f,e:text; ok:boolean;
y,x,v,j:array [1..1001] of integer;
BEGIN
assign(f,'energii.in');reset(f);assign(e,'energii.out');rewrite(e);
readln(f,g);readln(f,w);c:=10001;min:=-1;ok:=false; s:=0;cs:=0;
for t:=1 to g do
y[t]:=10000;
for i:=1 to g do
begin
readln(f,a,b);
v[i]:=a; j[i]:=b;
end;
for i:=1 to g do
if v[i]>=w then ok:=true;
if ok=true then
for i:=1 to g do
BEGIN
a:=v[i];b:=j[i];
if (a>=w) and (b<c) then
begin
c:=b;
min:=a;
end;
END;
if ok=false then
for i:=1 to g-1 do
for t:=1 to g do
if i<t then
BEGIN
if w>s then
begin
s:=s+v[i]+v[t];
cs:=cs+j[i]+j[t];
end;
if s>=w then
begin
x[t]:=t;
if cs<y[t] then y[t]:=cs;
s:=0;cs:=0;
end;
if w<s then y[t]:=10000;
END;
for t:=1 to g-1 do
for u:=t+1 to g do
if (y[t]>y[u]) and (y[t]<>10000) then
begin
aux2:=y[t];
y[t]:=y[u];
y[u]:=aux2;
end;
t:=1;
while y[t]=10000 do
t:=t+1;
if y[t]<>10000 then ala:=y[t];
if ok=false then write (e,ala);
if ok=true then write (e,c);
close(f);close(e);
end.