Halloween Sale
easy⏱ 15 mintypescriptchallengesproblem-solving-basic-
Sample case — your program reads stdin and prints to stdout.
Buy video games with decreasing prices: first game costs p, each next costs d less, but price never goes below m. With budget s, how many games can you buy?
Example: p=20, d=3, m=6, s=80 → Prices: 20, 17, 14, 11, 8, 6, 6... → Can buy: 20+17+14+11+8+6=76 → 6 games (can't afford 7th at 6)
Input format
Four space-separated integers: p d m s
Output format
A single integer: the number of games you can buy.
Constraints
1 ≤ m ≤ p ≤ 100, 1 ≤ d ≤ 100, 1 ≤ s ≤ 10⁶