Anthony Cicchetti
,
3 mins
,
Edited,
build up a group of "smallest required for x cost"
in this case, your map would look like
please hold

Anthony Cicchetti
,
Now
,
Edited,
cost | coins
1      | 1
2      | 1 + cost(1)
3      | 1 + cost(2) OR 3 (we pick 3)
4      | 1 + cost(3) OR 4 (we pick 4)
5      | 1 + cost(4) OR 3 + cost(2) OR 4 + cost(1) (we pick the last or the first)
6      | 1 + cost(5) OR 3 + cost(3) OR 4 + cost(2) (we pick 3 + cost(3), because that's fewer coins than the other options)