if(curr_value+curr_available_value<actual_target ||// Cannot possibly reach target with the amount remaining in the curr_available_value.
curr_value>actual_target +cost_of_change||// Selected value is out of range, go back and try other branch
if(curr_value+curr_available_value<selection_target ||// Cannot possibly reach target with the amount remaining in the curr_available_value.
curr_value>selection_target +cost_of_change||// Selected value is out of range, go back and try other branch
(curr_waste>best_waste&&(utxo_pool.at(0).fee-utxo_pool.at(0).long_term_fee)>0)){// Don't select things which we know will be more wasteful if the waste is increasing
backtrack=true;
}elseif(curr_value>=actual_target){// Selected value is within range
curr_waste+=(curr_value-actual_target);// This is the excess value which is added to the waste for the below comparison
}elseif(curr_value>=selection_target){// Selected value is within range
curr_waste+=(curr_value-selection_target);// This is the excess value which is added to the waste for the below comparison
// Adding another UTXO after this check could bring the waste down if the long term fee is higher than the current fee.
// However we are not going to explore that because this optimization for the waste is only done when we have hit our target
// value. Adding any more UTXOs will be just burning the UTXO; it will go entirely to fees. Thus we aren't going to