Official

A - Three Cards Editorial by evima


[1] Which cards should be used?

One should always use the cards with the three greatest integers.

We can show this as follows: if \(A_i > A_j\) and Card \(i\) is not chosen while Card \(j\) is chosen, one can replace Card \(j\) with Card \(i\) in the concatenated integer to make it greater.


[2] Computing the answer

Now that we know which three cards to use, we should try all six ways to arrange the cards and print the greatest result.

Note that arranging them in descending order may not be optimal.

For example, arranging \(9,9,10\) in descending order makes \(1099\), but we can make \(9910\) here.

The problem is now solved in \(\mathrm{O}(N)\) time.

posted:
last update: