Segmentation fault

Why is it giving segmentation fault?

You cannot make an integer array of size greater than 10^7. This will give segmentation fault. Reduce the array size to 10^5 and your code will work.
Refer this https://ide.codingblocks.com/s/253589

Got it.Thanks for the support.

This is still giving runtime error.

The test cases and constraints have been changed in this question. Genrally an array of size 10^9 cannot be made. But here n can range upto 10^9. So idea is to use hashmap for memo table and follow top down approach. Go through this discussion Exchanging coins

@omkarkhodwe
I guess pratyush has given the correct explanation.