/CATU2 - Cái túi 2

<Problem>

http://ntucoder.net/Problem/Details/1148
              Uses Crt,Math;
      Var n,m,i,j:longint;
          w,v:array[-100..100000] of longint;
          f:array[-100..1000,-100..1000] of longint;
      Begin
          readln(n,m);
          for i:=1 to n do read(w[i],v[i]);
          for i:=1 to n do
           begin
               for j:=1 to m do
                if (j>=w[i]) then
                 begin
                     f[i,j]:=max(f[i-1,j],f[i-1,j-w[i]]+v[i]);
                 end
                 else
                 f[i,j]:=f[i-1,j];
           end;
          writeln(f[n,m]);
          i:=n; j:=m;
          while (i>=1) and (j>=1) and (f[i,j]<>0) do
           begin
               while (f[i,j]=f[i-1,j]) do dec(i);
               write(i,' ');
               j:=j-w[i]; dec(i);
           end;
          readln;
      End.