Cheerio Contest 2 P2 - Cereal Boxes

View as PDF

Submit solution

Points: 3
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

Farmer Bob is buying cereal boxes at his local grocery store, which are priced in the following way:

  • The first M cereal boxes cost C dollars each
  • For every M boxes purchased, the price of any subsequent boxes is increased by I dollars

Bob only has Q dollars to spend. What is the maximum number of cereal boxes he can buy?

Constraints

For all subtasks:

  • 1M,C,I109
  • 1Q1012

Input Specification

The only line of input contains four integers M, C, I and Q.

Output Specification

Output the maximum number of cereal boxes Bob can buy.

Sample Input 1

Copy
2 1 3 35

Sample Output 1

Copy
7

Explanation for Sample 1

The prices of the cereal boxes Bob can buy are 1, 1, 4, 4, 7, 7 and 10 dollars respectively.

Sample Input 2

Copy
1 15 1 10

Sample Output 2

Copy
0

Comments

There are no comments at the moment.