I have been solving this problem and here's my code and my test cases — http://codeforces.net/contest/717/submission/25885501
I got a Time Limit Exceeded. And I'm not sure if it's because of the logic (because the processing is O(n) ) or if it's because the input is taking a lot of time. Can someone suggest ways on speedening up the code so that I don't get a TLE ?
Thanks