#P10335. [UESTCPC 2024] 取数游戏

[UESTCPC 2024] 取数游戏

Problem Description

There is a sequence of length nn. The weight of the ii-th number is aia_i. Two players, A and B, are playing a game. They will take turns performing operations on the sequence. Each player has two choices each turn:

  • Delete any two numbers ai,aja_i, a_j (ij)(i \neq j) from the sequence, and add a new number with weight ai+aja_i + a_j into the sequence. When there is only one number in the sequence, this operation cannot be performed.
  • Take away one number from the sequence, add up the weights of all remaining numbers and give the total to the opponent, then end the game.

If A ends up with a larger total weight, then A wins; otherwise, B wins.

A moves first. Determine whether A has a winning strategy. It is guaranteed that the sum of aia_i is odd.

Input Format

This problem contains multiple test cases.

The first line contains an integer TT (1T105)(1\leq T\leq 10^5), denoting the number of test cases.

For each test case, the input format is as follows.

The first line contains an integer nn (1n5×105)(1\leq n\leq 5 \times 10^5), denoting the initial length of the sequence.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai109)(1\leq a_i\leq 10^9), denoting the initial sequence.

It is guaranteed that n106\sum n\leq 10^6 and ai\sum a_i is odd.

Output Format

For each test case, if A has a winning strategy, output YES; otherwise output NO.

3
3 
3 6 4
2 
1 2
3
2 5 6
NO
YES
NO

Hint

The explanation for Sample 1 is as follows:

  • If A chooses the number with weight 33, then the weight B can get is 6+4=106+4=10.
  • If A chooses the number with weight 44, then the weight B can get is 3+6=93+6=9.
  • If A chooses the number with weight 66, then the weight B can get is 3+4=73+4=7.
  • If A chooses to merge weights 3,63,6, the sequence becomes 9,49,4. If B chooses the number with weight 99, then the weight A can get is 44.
  • If A chooses to merge weights 3,43,4, the sequence becomes 7,67,6. If B chooses the number with weight 77, then the weight A can get is 66.
  • If A chooses to merge weights 4,64,6, the sequence becomes 10,310,3. If B chooses the number with weight 1010, then the weight A can get is 33.

In all cases, B can obtain a higher total weight by playing optimally, so A cannot win.

The explanation for Sample 2 is as follows:

If A chooses the number with weight 22, then the weight B can get is 11.

Therefore, A has a winning strategy.

Translated by ChatGPT 5