Pagini recente » Cod sursa (job #1155146) | Cod sursa (job #2799914) | Cod sursa (job #1463034) | Cod sursa (job #388477) | Cod sursa (job #28241)
Cod sursa(job #28241)
type punct=record
a,o:longint;
end;
var v:array[1..5000] of punct;
y:array[1..5000] of longint;
f:text;
g,w,i,n,j:longint;
s1,s2,min:longint;
procedure citire;
begin
assign(f,'energii.in');reset(f);
readln(f,g);
readln(f,w);
for i:=1 to g do readln(f,v[i].a,v[i].o);
close(f);
end;
procedure sort(x,y:longint);
var i,j,m:longint;aux:punct;
begin
i:=x;j:=y;
m:=v[(x+y) div 2].o;
while i<=j do begin
while v[i].o<m do inc(i);
while m<v[j].o do dec(j);
if i<=j then begin
aux:=v[i];v[i]:=v[j];v[j]:=aux;
inc(i);dec(j);
end;
end;
if x<j then sort(x,j);
if i<y then sort(i,y);
end;
procedure determina;
begin
for i:=1 to g do begin
s1:=v[i].a;s2:=v[i].o;j:=i;
while (s1<w)and(j<=g) do begin
inc(j);
inc(s1,v[j].a);
inc(s2,v[j].o);
end;
if s1>=w then y[i]:=s2;
end;
end;
begin
citire;
sort(1,g);
for i:=1 to g do y[i]:=-1;
determina;
min:=maxint;
for i:=1 to g do if y[i]<min then min:=y[i];
assign(f,'energii.out');rewrite(f);
writeln(f,min);
close(f);
end.