#P10335. Winning Strategy in the Merging Game

    ID: 12339 Type: Default 1000ms 256MiB

Winning Strategy in the Merging Game

Winning Strategy in the Merging Game

Two players, A and B, play a game on a sequence of n numbers with weights \(a_1, a_2, \dots, a_n\). The sum \(S = \sum_{i=1}^n a_i\) is guaranteed to be odd. They alternate turns with A moving first, and on each turn a player may choose one of the following two operations:

  • Operation 1: Delete any two distinct numbers \(a_i\) and \(a_j\) (\(i \neq j\)) from the sequence and add a new number with weight \(a_i+a_j\) to the sequence. This operation is allowed only when the sequence contains at least two numbers.
  • Operation 2: Remove a single number from the sequence; then, the sum of all the remaining numbers is added to the opponent's total. The game ends immediately after this move.

At the end of the game, if A's total weight is greater than B's total weight, A wins; otherwise, B wins.

Determine whether player A has a winning strategy if both players play optimally.


Observation: Note that Operation 1 does not change the total sum \(S\) and Operation 2 divides \(S\) between the two players. If a player on his turn executes Operation 2 by taking a number \(x\) from the sequence, then his opponent will receive \(S-x\). Therefore, if a player uses Operation 2, he wins only if \(x > \frac{S}{2}\) (i.e. \(2x > S\)).

A key strategy for player A is to immediately execute Operation 2 if there exists a number greater than \(\frac{S}{2}\) in the sequence, guaranteeing a win. Conversely, if no such number exists, any immediate use of Operation 2 results in a loss. It can be proven that player A has a winning strategy if and only if the maximum element of the sequence, \(\max(a_i)\), satisfies \[ 2\max(a_i) > S. \]

inputFormat

The first line contains a single integer n (\(1 \le n \le 10^5\)), representing the number of elements in the sequence. The second line contains n space-separated positive integers \(a_1, a_2, \dots, a_n\). It is guaranteed that \(S = a_1+a_2+\dots+a_n\) is odd.

outputFormat

Output a single line containing Yes if player A has a winning strategy, or No otherwise.

sample

1
5
Yes