Cod sursa(job #5815)
program energetic;
var f,f1:text;
n,k,i,w,g,j,p,c:longint;
x:array[1..100,1..2] of integer;
begin
assign(f,'energii.in'); reset(f);
assign(f1,'energii.out'); rewrite(f1);
readln(f,n);
readln(f,w);
for i:=1 to n do readln(f,x[i,1],x[i,2]);
for i:=1 to n do
for j:=(i+1) to n do if x[i,1]/x[i,2]<x[j,1]/x[j,2] then begin
p:=x[i,1];
x[i,1]:=x[j,1];
x[j,1]:=p;
p:=x[i,2];
x[i,2]:=x[j,2];
x[j,2]:=p;
end;
i:=1;
c:=0;
p:=0;
while (p<w) and (i<=n) do begin
c:=c+x[i,2];
p:=p+x[i,1];
inc(i);
end;
if p>=w then writeln(f1,c)
else writeln(f1,'-1');
close(f);
close(f1);
end.