finished greedy.c