Problem Statement: Minimum Cost to Buy Ninja Blades
Ninja Yuki wants to purchase ninja blades at the Spring Fair in his village. Initially, he has 0 blades, and his goal is to buy 'N' blades. The merchant offers a peculiar pricing mechanism for the blades:
- Buy 1 blade for a cost of 'A'. This increases the total number of blades to 'K+1'.
- Buy additional 'K' blades for a cost of 'B', doubling the total to '2*K' blades.
Your task is to help Yuki find the minimum cost required to obtain exactly 'N' blades.
Input:
The first line contains an integer 'T', the number of test cases.
For each test case, the first line contains three space-separated integers 'N', 'A', and 'B':
- 'N' is the total number of blades Yuki wants.
- 'A' is the cost to add 1 blade.
- 'B' is the cost to double the current number of blades.
Output:
Return the minimum cost needed to acquire 'N' blades for each test case.
Example:
Input:
1
5 2 1
Output:
6
Explanation:
To acquire 5 blades at the minimum cost:
1) Add 1 blade to 0 blades at cost 2. Total: 1 blade, Cost: 2
2) Double 1 to get 2 blades at cost 1. Total: 2 blades, Cost: 3
3) Double 2 to get 4 blades at cost 1. Total: 4 blades, Cost: 4
4) Add 1 blade to get 5 blades at cost 2. Total: 5 blades, Cost: 6
Constraints:
- 1 <= 'T' <= 100
- 1 <= 'N' <= 104
- 0 <= 'A', 'B' <= 103
Note: Implement the function to calculate the minimum cost, as no output printing is required.
Be the first one to answer
Add answer anonymously...
Top Oyo Rooms Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
>
Oyo Rooms Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app