### protons's blog

By protons, history, 6 weeks ago,

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?

• -4

 » 6 weeks ago, # |   0 Auto comment: topic has been updated by protons (previous revision, new revision, compare).
 » 6 weeks ago, # |   0 It'll be easier if you add submission link as well
•  » » 6 weeks ago, # ^ |   +3 Your text to link here... This is my submission.I tried 3 times but the problem was not resolved.
•  » » » 6 weeks ago, # ^ |   0 Once Try this
•  » » 6 weeks ago, # ^ |   0 Just checked his submissions, and this one fits.
•  » » » 6 weeks ago, # ^ |   +3 Yes. Can you please tell me what actually went wrong?
 » 6 weeks ago, # |   +6 for (ll i = n; i >= 0; i--) Just change this to for (ll i = n; i >= 1; i--) 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
•  » » 6 weeks ago, # ^ |   +3 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.
•  » » » 6 weeks ago, # ^ |   +3 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.
•  » » » 6 weeks ago, # ^ |   +10 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.
 » 6 weeks ago, # |   +18 For the hundreds of such doubts that have preceded and will follow: the compiler is not buggy. It's always undefined behaviour.