The whole point of ios::sync_with_stdio(false) is that it unties it from scanf and other input methods. So you could be reading integers in weird order (and seem to be getting garbage values). A bit more on that here.
Also you have not declared the array before.I think that is why you got wrong answer.Basically you can use cin or scanf no problem .cin is slower than scanf that is only the difference.
The code as presented doesn’t even compile, so it’s clearly not representative of his actual code. I’d be wary of drawing too many conclusions from it
You can use cinorscanf “no problem”. You can even use both in the same program, provided you keep them in sync. But you can’t use them both ios::sync_with_stdio(false), or you will almost certainly getWA, as @galencolin said