13. (40 points) In a store where all items cost a whole number of rubles, two special offers are in effect:
1) A customer who buys at least three items can choose one item as a gift (free of charge), the cost of which does not exceed the minimum cost of the paid items;
2) A customer who buys exactly one item for no less than $N$ rubles receives a $20\%$ discount on the next purchase (of any number of items).

A customer, visiting the store for the first time, wants to purchase exactly four items with a total cost of 1000 rubles, the cheapest of which costs no less than 99 rubles. Determine the largest $N$, for which the second offer is more beneficial for him.
Answer: 504.

Solution: Let $S$ denote the total cost of the four items that interested the customer, and let $X$ be the minimum possible cost of the items. Being interested in exactly four items means that the customer can take advantage of either offer 1 or offer 2, but not both.

Let the items cost $s_{1}, s_{2}, s_{3}, s_{4}$ rubles, where $s_{1} \geqslant s_{2} \geqslant s_{3} \geqslant s_{4} \geqslant X$. In the case of the first special offer, the customer can only receive the item costing $s_{4}$ for free; thus, they will spend $S-s_{4}$ rubles. In the case of the second special offer, the customer will spend

$$
s_{i}+0.8\left(S-s_{i}\right)=0.2 s_{i}+0.8 S
$$

where $s_{i}$ is the minimum of the costs that are not less than $N$ (it exists, otherwise the second offer could not be used).

The second special offer is more beneficial to the customer if

$$
0.2 s_{i}+0.8 S<S-s_{4} \Leftrightarrow 0.2 s_{i}<0.2 S-s_{4} \Leftrightarrow s_{i}<S-5 s_{4}
$$

from which $N \leqslant s_{i}<S-5 s_{4} \leqslant S-5 X$, that is, $N \leqslant S-1-5 X=1000-1-5 \cdot 99=504$.

Let's check that the value 504 is achievable for $N$. Suppose the costs of the items are 99, 198, 199, and 504 rubles. And suppose the customer buys the item costing 504 rubles to use the second special offer. Then they will pay the amount $504+$ $+0.8 \cdot 496=900.8$, which is less than the amount spent in the case of using the first special offer $-1000-99=901$.