Clustering O(n*m) greedy alg working perfectly for problem 1