k-means clustering optimized for cost