In Problem D for the first test case (last case)
6 1 6 3 4 5 6 My answer was 10 everywhere (I tried on VsCode, GFG ide, Codechef ide) but when I was submitting it on Codeforces it was showing 16 and it wasted all of my time. Can Anyone please tell me what could be the probable reason?
It'll be easier if you add submission link as well
Your text to link here... This is my submission.
I tried 3 times but the problem was not resolved.
Just checked his submissions, and this one fits.
Yes. Can you please tell me what actually went wrong?
Just change this to
Since your array is 1 index based it just carrying value to 0 index and also during addition loop it is getting added to your answer , i resubmitted the corrected code but it failed on Case 2
Thank You callmepandey for pointing it out. But then how on all local ide (Vs code,gfg ide, etc...) it was showing 10.
All the time I was resubmitting it and getting WA and got ruined my contest.
Yes that's what i am thinking , for these kind of cases i prefer codechef ide, Actually yesterday even my G was giving correct on my Machine but WA in test 1 in Codeforces later i found that i actually haven't initialised values to one of my array , I guess local ide consider non initialised arrays value as 0 where this is not the case of Codeforces and other Judges.
When local variables are not initialised, a garbage value is stored. Since you are declaring your array locally, some garbage value is present at index 0. Since this is garbage, it differs in different platforms.
For the hundreds of such doubts that have preceded and will follow: the compiler is not buggy. It's always undefined behaviour.