Hi please disregard my previous comment. I thought the question was “why?” which is ambiguous.
Answering the real question:
- Why i%k? How did you come to this solution?
- The friends have to buy all flowers mimizing the cost.
- The problem becomes how to assign friends to flowers.
- This is easy, we just buy the cheapest flower first.
- Thats why we sort by price
- Now to minimize the cost of purchasing all flowers which increases with each additional flower purchased. We assign the ith flower to the i%k th friend.