function [ p2, w2 ] = knapsack_reorder ( p, w )

%*****************************************************************************80
%
%% knapsack_reorder() reorders knapsack data by "profit density".
%
%  Discussion:
%
%    This routine must be called to rearrange the data before calling
%    routines that handle a knapsack problem.
%
%    The "profit density" for object I is defined as P(I)/W(I).
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    24 October 2022
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Donald Kreher, Douglas Simpson,
%    Combinatorial Algorithms,
%    CRC Press, 1998,
%    ISBN: 0-8493-3988-X,
%    LC: QA164.K73.
%
%  Input:
%
%    integer P(N), the "profit" or value of each object.
%
%    integer W(N), the "weight" or cost of each object.
%
%  Output:
%
%    integer P2(N), the reordered "profit" or value of each object.
%
%    integer W2(N), the reordered "weight" or cost of each object.
%
  [ pw, i ] = sort (  p ./ w, 'descend' );
  w2 = w(i);
  p2 = p(i);

  return
end
