BASIC HELP πŸ™

1st Solution: 51715643 | CodeChef. (correct)
2nd Solution: 51715752 | CodeChef. (TLE)
The only difference in the above two code is at line no.4 (int in 1st and LL in 2nd)
Please tell me why this is happening ??
When to use LL and when to use int ??
What should i do to avoid such things from next time ??

EDIT
Different doubt in same question
1st. Solution: 51716541 | CodeChef. (correct)
2nd Solution: 51716633 | CodeChef (TLE)
Here the only difference is at line 29 . I dont think the way we write if else statement affect the time of our code . Then why such behaviour with different syntax

@ssjgz
Please help me with this :pray:

Did you try using '\n' instead of endl?

@suman_18733097
I tried it just now and it worked .
Can you please explain why so?

EDIT
It works only if i use int . If i use long long it fails

@aadarshsinha endl always flushes the stream where as \n simply puts a new line character to the stream
you can read more about it at : endl vs n in C++ - GeeksforGeeks

1 Like

Can you post links to the submissions where you used '\n'?
(one using int and other using long)

@suman_18733097
using int : Solution: 51724198 | CodeChef (correct)
using long long : Solution: 51724142 | CodeChef (TLE)
Difference at line no.3

I’ve tried every possible optimisation., I infer that it is probably due to additional overhead while operating on long long variables (64 bits).

2 Likes

Thanks for helping me tough i still have many doubts but I have learn few new concepts .

1 Like

@aadarshsinha check the this solution but using long long

If you use \n instead of endl
then your solution is accepted.

Solution: https://www.codechef.com/viewsolution/51727325

It means , it is not matter whether you use int or long

happy coding

@praveen_86
Any comments on this ?

This is getting Weird.
I don’t see any significant difference in the following submissions.
https://www.codechef.com/viewsolution/51727603
https://www.codechef.com/viewsolution/51727633

But the verdict is different. The first one runs in 0.81s, it is not close to 1.0s too.

@ssjgz , can you help?

1 Like