I was trying to solve IZHO19_sortbooks on oj.uz. In problem $$$n, m <= 10^6$$$ and Time Limit is 3s.
I have 2 questions: Why I got full score? And why if I change code a bit or submit exactly the same code doesn't get the same result?
Time complexity of my solution is $$$O(n \cdot log_2(n) + m \cdot \log_2(n)^2)$$$ and memory usage is exactly $$$256$$$ MB($$$262 144$$$ KB). It should be $$$TLE$$$ because $$$10^6 \cdot \log_2(10^6)^2 = 397 267 425.6 > 3 \cdot 10^8$$$ and it's almost $$$MLE$$$ (if it used just $$$1$$$ KB more). What's more weird is if I change my code a bit it won't get full score because of $$$MLE$$$. Even if I submit a code again, it might not get the same result.
Following 2 codes are same but $$$1^{st}$$$ submission got $$$100$$$, $$$2^{nd}$$$ is $$$MLE$$$:
$$$1^{st}$$$ submission:1096192 got $$$100$$$ pts, $$$2^{nd}$$$ submission:1096203 got $$$77$$$ pts and it's $$$MLE$$$.
You can look my other submission too: link. Explanation of my approach is on comments.