problem : CodeChef: Practical coding for everyone
TLE with int : CodeChef: Practical coding for everyone
AC with long long : CodeChef: Practical coding for everyone
problem : CodeChef: Practical coding for everyone
TLE with int : CodeChef: Practical coding for everyone
AC with long long : CodeChef: Practical coding for everyone
Hello @anon94212090,
As you can see in the problem statement the value of A[i] is <= 10^18. The range of int is a Just a bit more than 10^9, whereas the range of long long int is a bit more than 10^18. Thats why your code gives TLE.
yes but in that case it sould have been WA, how TLE?
As integer can’t store values greater than 10^9, the program will overflow and result in giving TLE 
That’s not really an answer, as there are plenty of situations where an overflow occurs but causes a WA instead of a TLE ![]()
(Also, technically, no overflow actually occurs - the act of reading a too-large value into a variable is perfectly well-defined).
@anon94212090 - try with the following test input:
2
3
173943434324324324 2 7
2
1 2
The fact that it causes TLE in this case relies on some Undefined Behaviour, so might not occur on all platforms.
Explanation:
T is read successfullyT = 1, we goes through the loop and read N successfully.int variable x, and the value 173943434324324324 is too large to fit into an int.x to std::numeric_limits<int>::max() and to set the failbit of cin to true. [1]cins failbit is true, any subsequent attempt to read values into a variable via cin will fail, leaving that variable unchanged. [2]N is now -1.T, and go through the loop the final time.N is not initialised, so we don’t know its value. However, most compilers will not change the stack address of N, so it still maintains its previous value - -1.N via cin, but cins failbit is still true - hence, the read fails, and N maintains its value - that is, -1.The loop
while (N--)
for N = -1 will almost certainly timeout before it completes (in fact, whether it completes at all is Undefined).
[1] - see here. In particular:
[2] - see here. In particular:
thankyou that was wholesum information.