Minimum Coin Exchange Problem

I have few doubts related to this problem, with respect to this problem https://cses.fi/problemset/task/1634/

1 -> https://ide.codingblocks.com/s/231523
when im taking ans var as INT_MAX why am i getting a wrong ans, and if i replace it with 1e9 definition , it is working fine, im talking this with respect to line number 12

2 -> another question is how do i apply a condition that if im unable to change my money in coins then return -1

suppose consider a test case as

2 10
3 6

i want my ans as -1

@Bhavya_Goel inside your function when money<c[i] for all i’s then your ans will never get updated and it will remain as INT_MAX and when you store dp[money] = ans+1 it will cross int limit as ans is max of int hence taking INT_MAX is causing you problem here.
inside main function check if your function is returning inf+1 (if you are taking ans as inf) as answer means you never found the change hence print -1 in that case.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.