Getting TLE in CF round 173 Div 2 B

Hi,

(I’m a newbie programmer here and this is my first post, so please let me know if I commit any errors in the placement etc of this doubt.)

I have a doubt in Codeforces Round 173 Div 2B - the problem can be found here. My solution (which is getting Time limit exceeded is here. The official solution (seemingly so from the editorial) is here.

My doubts are:

  1. The official solution does not consider any case in which “-1” is the output, seemingly?
  2. My solution seems to be of complexity O(n), but it still gets TLE? Bound of n is 10^6 in the problem.

If someone can help me understand this, thanks a lot! :slight_smile:

Hi,

I think I got my response to the above question - It’s because cin and cout aren’t fast enough to take input. I needed to use scanf/printf or cin.tie(0) instead. Admin, please close this thread! (I don’t know how to)

There’s an option close question near edit button, which will close your thread.

You need some karma to close your thread afaik.