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

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

``````endl
``````

``````\n
``````

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:

``````	ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

``````
1 Like

using
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
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
Current Solution : Solution: 42874044 | CodeChef

https://www.codechef.com/viewsolution/42874262

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

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
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.

1 Like