I've been trying to solve Problem A of yesterday's finals. My solution is very similar to Tourist's solution (~33:00). My code is here. It TLEs on test case 12, but I can't seem to figure out why, I'm pretty sure the complexity is NlogN. In all likelihood, it's down to some edge case/infinite loop. If somebody could help me figure out the issue, I'd be very grateful. Thanks in advance.