## Editorial for An Animal Contest 2 P4 - Koala Gambling

**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.**

Author:

We split this problem into two cases:

Odd : We arrange the array in non decreasing order. For example, let the array be such that . It is easy to see that if Ken picks , it is always optimal for his opponent to pick , the next largest available number. If his opponent picks , he leaves the current largest number in the line, , available to Ken. Ken then picks , causing his opponent to pick . Finally, Ken picks . Since Ken's total after the first moves is always greater or equal to his opponent's, the selection of the or smallest element guarantees him the win.

Even : We first realize the only case where the answer is is when all elements in the array are the same.

We start by sorting the array in non decreasing order. Let us call the first half of the array (the larger half) and the second half (the smaller half) . We arrange in the following manner: .

To understand why, consider that on each of Ken's turns, he picks an element from . Then, his opponent is always left with an element from . This process repeats until Ken selects the entire array and his opponent selects the entire array . Since all elements in are greater than or equal to all elements in and the array consists of more than one distinct number, the sum of elements in must be strictly greater than the sum of elements in , as desired.

**Time Complexity:**

## Comments