C++/Greedy Alogirhm(3)