we have few items sorted in a particular order... all items have associated prices p(p1, p2...pn) say
item1 - p1
item2 - p2
. . .
itemn - pn
we have x amount to buy items. and initially 0 < x <= p
after each iteration x will become x-p1, x-(p1+p2)....x-(p1+p2+...pn)....at any point if we find that any itemK with price pk > current value of x we will remove that item from the list and buy the next item
we will again run this till either x=0 (amount gets exhausted) or list is empty (all items are of value > current value of x and are removed from the list)
function will return no. of purchases per items
right now i can think of a python dict/list based approach to do this, where we will loop through the above scenario, do a .remove(item) where ever applicable.
but its too much iteration hungry. wondering if theres a better mathematical approach to find this efficiently.