Bananas at the Plaza
Submit solution
Points:
30
Time limit:
0.2s
Memory limit:
256M
Author:
Problem type
Allowed languages
C, C++
At a school event in the town square of Mayagüez, a stand sells bananas at an increasing price within each purchase. The first banana costs k dollars, the second costs 2k, the third costs 3k, and so on. Banana number i costs i·k dollars.
You want to buy exactly w bananas and have n dollars. Find how much additional money you need. If you already have enough, the answer is zero.
Input
One line containing integers k, n and w, in that order.
Output
Print one integer: the additional amount of money needed.
Constraints
1 ≤ k, w ≤ 1 000; 0 ≤ n ≤ 1 000 000 000.
Example
| Input Example | Output Example |
|---|---|
| 2 10 4 | 10 |
| 3 30 4 | 0 |
The available money covers the total cost.
Source
Adapted for OiPR 2026. Codeforces 546A — Soldier and Bananas.
Comments