as n,m,x,y are all less than 10^9, they can be stored as int. i took only have and cost to be long long int in my code and it was not working fine.
but when i took everything to be long long int, it worked fine.
acc to me, if integer type variables are accumulating in a variable, only that should be taken as long long int. so, here only ‘have’ and ‘cost’ should be int.
link to my code -
correct output with all long long type - 
incorrect output -
