Editorial for An Animal Contest 3 P3 - Monkey Market
Submitting an official solution before solving the problem yourself is a bannable offence.
We notice that it is always optimal to buy at the smallest prices and sell at the largest prices. We sort the numbers and place them in an alternating fashion like
S L S L, where
S denotes one of the smallest prices and vice versa for
L. Since order does not matter for multiplication and division, it suffices to place the numbers in any order that satisfies the alternating fashion.