codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1472D.md (2358B)


      1 Source: https://codeforces.com/problemset/problem/1472/D
      2 
      3 D. Even-Odd Game
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 During their New Year holidays, Alice and Bob play the following game using an array $a$ of $n$ integers:
     22 
     23 * Players take turns, Alice moves first.
     24 * Each turn a player chooses any element and removes it from the array.
     25 * If Alice chooses even value, then she adds it to her score. If the chosen value is odd, Alice's score does not change.
     26 * Similarly, if Bob chooses odd value, then he adds it to his score. If the chosen value is even, then Bob's score does not change.
     27 
     28 If there are no numbers left in the array, then the game ends. The player with the highest score wins. If the scores of the players are equal, then a draw is declared.
     29 
     30 For example, if $n = 4$ and $a = [5, 2, 7, 3]$, then the game could go as follows (there are other options):
     31 
     32 * On the first move, Alice chooses $2$ and get two points. Her score is now $2$. The array $a$ is now $[5, 7, 3]$.
     33 * On the second move, Bob chooses $5$ and get five points. His score is now $5$. The array $a$ is now $[7, 3]$.
     34 * On the third move, Alice chooses $7$ and get no points. Her score is now $2$. The array $a$ is now $[3]$.
     35 * On the last move, Bob chooses $3$ and get three points. His score is now $8$. The array $a$ is empty now.
     36 * Since Bob has more points at the end of the game, he is the winner.
     37 
     38 You want to find out who will win if both players play optimally. Note that there may be duplicate numbers in the array.
     39 
     40 Input
     41 
     42 The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow.
     43 
     44 The first line of each test case contains an integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $a$.
     45 
     46 The next line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — the array $a$ used to play the game.
     47 
     48 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
     49 
     50 Output
     51 
     52 For each test case, output on a separate line:
     53 
     54 * "Alice" if Alice wins with the optimal play;
     55 * "Bob" if Bob wins with the optimal play;
     56 * "Tie", if a tie is declared during the optimal play.
     57 
     58 Example
     59 
     60 Input
     61 
     62 ```
     63 4
     64 4
     65 5 2 7 3
     66 3
     67 3 2 1
     68 4
     69 2 2 2 2
     70 2
     71 7 8
     72 ```
     73 
     74 Output
     75 
     76 ```
     77 Bob
     78 Tie
     79 Alice
     80 Alice
     81 ```