Hey guys,
The following submission keeps getting TLE even though it has the same time complexity as the official solution ($$$\mathcal{O}(n)$$$)
Submission: https://mirror.codeforces.com/contest/1430/submission/104613827
Problem: https://mirror.codeforces.com/problemset/problem/1430/C
Any ideas about what's going on?
Java's Scanner is extremely slow; use BufferedReader instead.
I tried using BufferedReader but I still get TLE.
Submission: https://mirror.codeforces.com/problemset/submission/1430/104614811
Due to the large number of output lines, it turns out you also need to use PrintWriter for more efficient output. See here for an AC version.
Thank you so much, I've been banging my head on this for a while.