Please Explain the difference between these 2 solutions

These are two solutions that i want to know the difference between.
Contest Link : Contest Page | CodeChef

Mine that i wrote during the contest : Solution: 42872888 | CodeChef
The one i found after the contest for reference : Solution: 42834421 | CodeChef

From what i understand i have basically done everything the same as the reference code, but i am getting a TLE while they are not, so can some1 please explain why?

Extremely sorry if the answer is rather simple or stupid and due to my ignorance, i am new to this
Thank you in advance :slight_smile:

The time limits on this were very tight and there was a lot of input and output: it’s likely that your use of


instead of:


is at least part of the reason why yours got a TLE.

@ssjgz also can u explain why we usually get TLE using while loop but not while using for
loop i have done prob. on this only difference is loop (include.’\n’)
for iterating test case

1 Like

possibly, but their answer takes less than 0.2s, when mine gets a TLE, moreover on the test case where i did get an answer mine was wrong.
either way i just tried using “/n” instead of endl and still a TLE

Also try using fast input, like they did:

1 Like

helps with the TLE, but my answer is still wrong somehow, i have used their function and mine and compared the arrays, which seem to be the exact same.
can you please also explain what exactly this bit of code does? sad to see that the code got rejected because of this :frowning:
Current Solution : Solution: 42874044 | CodeChef

Check your conditions

  1. You are running loops till dpsize-1 (and ignore the last element)
  2. Your condition does not have a equality at the end.


There should be an (y >= givex(x)) because if suppose the TC is 6 3 then it will not give any answer.

1 Like

i see, when i had coded this during the contest i had used dpsize = 1e6+2 which is why this was a mistake, and i overlooked the = in my if condition, Thank you so much :smiley:
is their a possibility that the fast input may make the code not work or should i always include it?

Also, if you really want to see naïve solution, you can check my approach too. Here it is: Solution: 42770754 | CodeChef. Do tell me if you don’t get it. :slight_smile:

1 Like