some refactoring to greedy min weighted sum count algorythm