Merge Sort, Code crashing for large values

This is my attempt at the merge sort problem :

it follows the lecture exactly, although the problem consraints say 10^9 for A[i]… and somehow the code keeps crashing for all values large.
i have tried using long long type to store all values.
Please tell me how i can make this more efficient and accomodate large values.
Thanks!

@ilovetocode
while(i<=j){

    temp[t++]=arr[i++];

}

while(x<=y){

    temp[t++]=arr[i++];

}

In the second while loop, you have made an error. temp[t++] = arr[x++], this is the required line but you have used i in place of x. Please correct that.

And secondly, make the temp array a global array because declaring it time and again takes up a lot of time which is not wise. This would solve the issue.

In case my answer was able to resolve your query, please mark the doubt as resolved.

Hi Kshitij, Thanks for the correction, i have now updated my code and it seems to be testing fine.