SPOJ SMALL Overflow help

I have attempted the problem ‘SMALL’ from SPOJ link. Here is the code.

It works fine on CodeBlocks but gives runtime error on ideone, due to overflow.

For example, there is no output for inputs like 5000 or 10000. How do I correct this?

P.S. I’ve just recently started coding in C++ having knowledge only in C so suggestions on making the code ‘cleaner’ will be helpful.

solved… needed to increase array size