Soldier and Bananas
EasyRating 800CodeforcesMath & Implementation
Approach hintTry it first, then revealHide
The i-th banana costs i * k, so the total is k times an arithmetic series; borrow only the amount by which it exceeds n, and never a negative amount.