The setup is that, given a list of N
objects like
class Mine
{
public int Distance { get; set; } // from river
public int Gold { get; set;
When you consolidate mine i into mine j, the amount of gold in the mine j is increased. This makes consolidations from mine j to other mines more expensive potentially making the ordering of the mines by the move cost invalid. To fix this, you could re-sort the list of mines at the beginning of each iteration of your while-loop.