/AGAR - Agar.io

<Problem>

http://ntucoder.net/Problem/Details/4479
              Uses Crt;
        Var n,i,j,count,restric:longint; s,kt,vitri_goc:array[-100..100001] of longint; a,b:int64;
        Procedure Sort(l,r:longint);
        var tg,x,i,j:longint;
        begin
            i:=l; j:=r; x:=s[(l+r) div 2];
            repeat
                while s[i]<x do inc(i); while x<s[j] do dec(j);
                if i<=j then
                 begin
                    tg:=s[i]; s[i]:=s[j]; s[j]:=tg;
                    tg:=vitri_goc[i]; vitri_goc[i]:=vitri_goc[j]; vitri_goc[j]:=tg;
                    inc(i); dec(j);
                 end;
            until i>j;
            if l<j then sort(l,j);
            if i<r then sort(i,r);
        end;
        Function Tim(l,r:longint):longint;
        var  tg,vt:longint;
        begin
            while l<=r do
             begin
                 tg:=(L+r) div 2;
                 if s[tg]<a then vt:=tg;
                 if s[tg]<a then l:=tg+1
                  else r:=tg-1;
             end;
            Tim:=vt;
        end;
        Procedure Check;
        var i:longint;
        begin
            writeln(count);
            for i:=1 to n do
             if kt[i]=1 then write(vitri_goc[i],' ');
        end;
        Begin
            readln(n,a,b);
            for i:=1 to n do
             begin
                read(s[i]);
                vitri_goc[i]:=i;
             end;
            if a>b then
             begin
                 writeln(0);
                 exit;
             end;
            sort(1,n);
            //for i:=1 to n do write(s[i],' '); writeln;
            //writeln(tim(1,n));
            //s[0]:=-maxlongint; s[n+1]:=maxlongint;
            //i:=tim(0,n+1);
        
            //writeln(i,' ',j);
            for i:=0 to n do if s[i+1]>=a then break; j:=i+1;
            count:=0;
            while i<>0 do
             begin
                 if kt[i]=0 then
                  begin
                      kt[i]:=1;
                      a:=a+s[i];
                      inc(count);
                      restric:=j;
                  end;
                  if a>b then begin check; exit; end;
                 while (j<=n) and (a>s[j]) do inc(j);
                 if restric<>j then i:=j-1 else dec(i);
             end;
            writeln(-1);
            readln;
        End.