Given n drinks, find optimum way to spend money if for each drink the price and the expiration date is given Let's say we are given $n$ types of drinks, integer $m$ representing the budget we have and integer $d$ representing the cost of delivery when we order some drinks. For each of the $n$ drinks we are given $P_i \text{ the price of i-th drink and } E_i - \text{expire date}$. For example $(3, 2)$ is representing drink with price $3$ for one bottle and the second number means that this drink can be used at most $2$ days after we buy it. One cannot drink drinks that have expired date of usage and one must drink exactly once per day.

We can order as many drinks as we want from each type, but each time we order we are paying $d$ dollars for delivery. Notice that the delivery doesn't matter in the day, so we can buy drink with exprite date $2$ and used it either today, tomorrow, or the day after tomorrow.

We want to maximize the number of drinks we will buy and drink.

I think that this problem can be solved with greedy strategy, but I'm not able to find anything that can lead to correct result and good time complexity.

Here are some things that I got so far:

We don't want to buy things that will be expired, so from each drink with price $P_i$ we will spend at most $P_i \cdot(E_i + 1)$

Because we may have big budget, it is good to find one way of buying drinks and use it couple times, until we don't run out of money from the budget.

We will first buy the cheaper drinks and for the more expensive ones we should decide should we make a new order, or buy some drinks from the next type.

I didn't got anything that lead to correct strategy, so please share some of your ideas.
It’s not very difficult really, assuming we only care about the cost and don’t have any preferences for drinks. 

If we want to make a single order that lasts for n days as cheap as possible, we order the cheapest drink with expiry k, for each 0 &lt;= k &lt; n. That supply costs the cost of the drinks plus d. We can calculate this cost for 1 &lt;= n &lt;= E+1, where E is the longest expiry of any drink. 

If we want drinks for N days, we make 1 or more orders to minimise the total cost. We may assume the orders are ordered by size in descending order (and if we find the best sequence of orders with this restriction, we can rearrange it any way we like). Finding the best orders is now a simple dynamic programming problem. 

If you are looking for something complicated, it’s not needed.