title: Algorithm to share/settle expenses among a group
body: <p>I am looking forward for an algorithm for the below problem.</p>
  <p>Problem: There will be a set of people who owe each other some money or none. Now, I need an algorithm (the best and neat) to settle expense among this group.</p>
  <pre><code>Person AmtSpent
  ------ ---------
  A       400  
  B      1000  
  C       100  
  Total  1500
  </code></pre>
  <p>Now, expense per person is 1500/3 = 500. Meaning B to give A 100. B to give C 400. I know, I can start with the least spent amount and work forward.</p>
  <p>Can some one point me the best one if you have.</p>
  <p>To sum up,</p>
  <ol>
  <li>Find the total expense, and expense per head.</li>
  <li>Find the amount each owe or outstanding (-ve denote outstanding).</li>
  <li>Start with the least +ve amount. Allocate it to the -ve amount.</li>
  <li>Keep repeating step 3, until you run out of -ve amount.<br />
  s. Move to next bigger +ve number. Keep repeating 3 &amp; 4 until there are +ve numbers.</li>
  </ol>
  <p>Or is there any better way to do?</p>