We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Chocolate Feast

Chocolate Feast

Problem
Submissions
Leaderboard
Discussions
Editorial
Topics

Little Bobby loves chocolate. He frequently goes to his favorite store, Penny Auntie, to buy them. They are having a promotion at Penny Auntie. If Bobby saves enough wrappers, he can turn them in for a free chocolate.

Example


He has to spend, bars cost , and he can turn in wrappers to receive another bar. Initially, he buys bars and has wrappers after eating them. He turns in of them, leaving him with , for more bars. After eating those two, he has wrappers, turns in leaving him with wrapper and his new bar. Once he eats that one, he has wrappers and turns them in for another bar. After eating that one, he only has wrapper, and his feast ends. Overall, he has eaten bars.

Function Description

Complete the chocolateFeast function in the editor below.

chocolateFeast has the following parameter(s):

  • int n: Bobby's initial amount of money
  • int c: the cost of a chocolate bar
  • int m: the number of wrappers he can turn in for a free bar

Returns

  • int: the number of chocolates Bobby can eat after taking full advantage of the promotion

Note: Little Bobby will always turn in his wrappers if he has enough to get a free chocolate.

Input Format

The first line contains an integer, , the number of test cases to analyze.
Each of the next lines contains three space-separated integers: , , and . They represent money to spend, cost of a chocolate, and the number of wrappers he can turn in for a free chocolate.

Constraints

Sample Input

STDIN   Function
-----   --------
3       t = 3 (test cases)
10 2 5  n = 10, c = 2, m = 5 (first test case)
12 4 4  n = 12, c = 4, m = 4 (second test case)
6 2 2   n = 6,  c = 2, m = 2 (third test case)

Sample Output

6
3
5

Explanation

Bobby makes the following trips to the store:

  1. He spends on chocolates at apiece. He then eats them and exchanges all wrappers to get more. He eats chocolates.
  2. He spends his on chocolates at apiece. He has wrappers, but needs to trade for his next chocolate. He eats chocolates.
  3. He spends on chocolates at apiece. He then exchanges of the wrappers for additional piece. Next, he uses his third leftover chocolate wrapper from his initial purchase with the wrapper from his trade-in to do a second trade-in for more piece. At this point he has wrapper left, which is not enough to perform another trade-in. He eats chocolates.

Author

shashank21j

Difficulty

Easy

Max Score

25

Submitted By

152100

Need Help?


View discussions
View editorial
View top submissions
RESOURCES

  • Div Mod

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits

Choose a translation


  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy