Persistent optimizer
Here is a sheet that should work. You can sort by clicking the green triangle in Column E and sorting Z->A. Or once you copy this to your account, I created a script you can add that will auto sort after you add the cost value.
https://docs.google.com/spreadsheets/d/1fOunDA5uFF7juVjyP2ZUKAWp0j7X_AJ1WuIdnI_HS7I/edit?usp=sharing
Did it work? Or does it need adjustment?