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
  • Practice
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. Algorithms
  3. Implementation
  4. Halloween Sale

Halloween Sale

Problem
Submissions
Leaderboard
Discussions
Editorial

You wish to buy video games from the famous online video game store Mist.

Usually, all games are sold at the same price, dollars. However, they are planning to have the seasonal Halloween Sale next month in which you can buy games at a cheaper price. Specifically, the first game will cost dollars, and every subsequent game will cost dollars less than the previous one. This continues until the cost becomes less than or equal to dollars, after which every game will cost dollars. How many games can you buy during the Halloween Sale?

Example



.

The following are the costs of the first , in order:

Start at units cost, reduce that by units each iteration until reaching a minimum possible price, . Starting with units of currency in your Mist wallet, you can buy 5 games: .

Function Description

Complete the howManyGames function in the editor below.

howManyGames has the following parameters:

  • int p: the price of the first game
  • int d: the discount from the previous game price
  • int m: the minimum cost of a game
  • int s: the starting budget

Input Format

The first and only line of input contains four space-separated integers , , and .

Constraints

Sample Input 0

20 3 6 80

Sample Output 0

6

Explanation 0

Assumptions other than starting funds, , match the example in the problem statement. With a budget of , you can buy games at a cost of . A game for an additional units exceeds the budget.

Sample Input 1

20 3 6 85

Sample Output 1

7

Explanation 1

This is the same as the previous case, except this time the starting budget units of currency. This time, you can buy games since they cost . An additional game at units will exceed the budget.

Author

kevinsogo

Difficulty

Easy

Max Score

20

Submitted By

54388

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature