Hello there! I am trying to solve problem IOI 2000 Car. It is not very hard, but my source keeps getting TLE8, and I do not know how to improve my code. I think its complexy is O(NlgN+NM).
Can anyone help me? Here is my source with comments. My idea is greedy, We are to find W numbers making chains, so that we can shift each chain and get at least W-1 numbers got to there place. I would be happy to any help. You can download testdata on official site.