Fixed bugs, reached best solution possible, O(m log n) guaranteed.