For the question www.codechef.com/problems/CHOC the solution submitted bt me is http://www.codechef.com/viewsolution/6020829 and I saw another solution http://www.codechef.com/viewsolution/6020272 in C++ with exactly same logic and kind of same code(differnce being C++). The solution in C++ is accepted whereas I am repeatedly getting TLE…
I think you are using LONG LONG datatype, which is slow. Change it to INT and it will pass.
Definitely the difference is not just C++. Because your code which is in C, doesn’t even get AC in C++ (still gets TLE). So, there got be some other difference.
The constraints are 10^5…i guess long long or atleast long is a better option than int…correct me if i am wrong…
The second code is in C++ which is accepted…if u can see there isn’t much of a difference between the two codes…
You are using long long datatype, it is 64 bit and supports upto 18,446,744,073,709,551,616.
int datatype is 32 bit and is supports 4294967296 ( both are considering gcc4.9.2).
The problem does not require you to use long long datatype, it can be done using int.
As this problem has very restrict time constraint, you should use int because long long is slower than int.
Also you are allocating more memory to the array than needed (
1 ≤ N ≤ 10000 ).
Here is my AC solution during contest which uses int datatype.
Check this wiki article if you want to know more about data type size and range.
Thanks…will change the data type and submit it again…still have much to know about the range of data types…Thanks anyways…
Happy to help.