Picu bank question, binary search

my answer is differing by 1 in some test cases, can someone pls take a look at my code. What’s wrong in my approach.

My code : https://ide.codingblocks.com/s/209446

problem link: https://www.hackerearth.com/practice/algorithms/searching/binary-search/practice-problems/algorithm/picu-bank-09e29493/

@amitqy hey your logic is not correct,use this logic ,its simply maths:
Our task is to calculate the number of days needed to make the dollar amount to at least X in the bank account.

The first obvious case is if amount of dollar we are interested for - X is less than or equal to initial dollar ( D ) , then we do not need to wait for further days. So, the answer will be 0 in this case.

In other cases, If you think straight forward bruteforce apporach then, it would be taking initial summation as D, keep on adding value A for first M month and add value B on M+1 th day and repeat similar scenario again untill we reach amount greater than or equal to X. This will not definitely set into our time limit as there are lots of testcases.

For better approach , we will first subtract D from X which makes our calculation easier. Now, we can first take out every (M+1) days segments in a chunks. So, we need (MA+B) amount of money in a particular chunk. To find total such chunt needed , we can divide current X by (MA+B) and take integer part. the remaining amount for making X will be will be filled up using amount A.
Also for reference here is code with comments:

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.