Editorial for An Animal Contest 3 P3 - Monkey Market
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
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.
Time Complexity:
Comments