← All problemsSign in

Bulk Discount

CodeChefRating 1138Open on judge ↗

A shop has $N$ items for sale. The $i$-th item has a cost of $A_i$. You would like to purchase all $N$ items. The shop offers a discount: whenever an item is bought, all future purchases have their costs reduced by $1$. However, the cost of an item also cannot fall below $0$. You can buy the items **in any order** you like. What's the minimum possible cost of purchasing all $N$ items? ### Inp

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start