Just an observer of this problem. I would liken it to a check book with an
overdraft condition. If overdrawn by 500 what combination of checks issued
and outstanding would minimize the OD charges or the opposite condition what
combiniation would maximize it. It seems my bank uses a logic of
maximization!
I would summarize totals for each receipt first, then sort the receipts in
decending order. Cycle down the list with the first less than or equal to
OD. Repeat until total satisfied.