Consider using a greedy algorithm.