improved greedy.cpp with multiple plans