greedy algorithm, implement it in a hard way but finally solve it perfectly, goood.