Greedy with new operator definition and cost/penalty. Runnable version.