Diwali Sale

0

0 votes
Easy
Problem

You wish to buy dresses from the famous store nearby.

Usually, all dresses are sold at the same price,p dollars. However, they are planning to have the seasonal Diwali Sale next month in which you can buy dresses at a cheaper price. Specifically, the first dress you buy during the sale will be sold at p dollars, but every subsequent dress you buy will be sold at exactly d dollars less than the cost of the previous one you bought. This will continue until the cost becomes less than or equal to m dollars, after which every dress you buy will cost m dollars each.

For example, if p=20, d=3 and , m=6 then the following are the costs of the first 11 dresses you buy, in order: 20,17,14,11,8,6,6,6,6,6,6

You have s dollars in your wallet. How many dresses can you buy during the Diwali Sale?

Input Format:

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

p,d,m and s.

Constraints:

1≤mp≤100

1≤d≤100

1≤s≤104

Output Format:

Print a single line containing a single integer denoting the maximum number of dresses you can buy.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

We have p=20,d=3 and m=6, the same as in the problem statement. We also have s=80 dollars. We can buy 6 dresses since they cost 20+17+14+11+8+6=76 dollars. However, we cannot buy a 7th dress. Thus, the answer is 6.

Editor Image

?