Picu Bank
Practice
3.4 (98 votes)
Algorithms
Binary search
Easy
Math
Searching
Problem
26% Success 31229 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You have $$D$$ dollars with you. You want to put it into a Bank, namely Picu Bank. This bank has a peculiar behavior for interest. Regardless of the Bank deposit amount, every month it adds $$A$$ dollars to your bank account and this continues till $$M$$ months. Exaxtly on $$ M+1 $$ months, it adds $$B$$ dollars $$ (B < A) $$ to your bank account. This scanario repeats again in same manner.( i.e on the $$ (M+2)^{th}$$ month $$A$$ dollars are added, and so on.. ). Your task is to find out how many months does it take for the dollar amount to reach at least $$X$$, in the bank account .    

Input:

Input starts with an integer $$ T (1 \le T \le 100000) $$, denoting the number of test cases.  Each case starts with 5 integers $$D, A, M, B$$ , and $$ X $$ as described in problem statement.

 

Constraints:

  • $$ 1 \le D,M,X \le 10^9 $$
  • $$ 1 \le B < A \le 10^9 $$ 

Output:

For each case of input minimum number of months needed to reach dollar value of at least X in a single line.

Note that the Expected Output feature of Custom Invocation is not supported for this contest. 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
15 votes
Tags:
AlgorithmsBinary SearchEasySearchingTwo pointer
Points:20
86 votes
Tags:
ApprovedBinary SearchEasyOpenSorting
Points:20
13 votes
Tags:
AlgorithmsBinary SearchEasySearchingsearching