Odd Cards

5

2 votes
Algorithms, Sorting, Advanced Sorting
Problem

There are N cards, where N=2k+1 is an odd integer 3.

Also, there are two arrays A=[a1,a2,...,aN] and H=[h1,h2,...,hN].

Here ai and hi represent the attack point and the health point of the ith card, respectively.

Assume that Alice choose k cards first, and then Bob accepts the other k+1 cards automatically.

Let ha and hb be the minimal health points of Alice and Bob, respectively.

Suppose that the total power of Alice is obtained by multiplyng ha by the sum of the attack points of Alice's cards.

Similarly, the power of Bob is obtained by multiplyng hb by the sum of the attack points of his cards.

Then, determine the winner if both players play optimally.

 

Constraints

  • 1T1000
  • 3N105
  • 1ai105
  • 1hi105
  •  The sum of N across all test cases does not exceed 2105.

Input Format

  • The first line contains a single integer T —- the number of test cases.
  • For each testcase:
    • The first line contains one odd integer N —- the length of the arrays.
    • The second line contains N positive integers a1,a2,...,aN.
    • The third line contains N positive integers h1,h2,...,hN.

  • The sum of n over all test cases does not exceed 2105.

Output Format

  • For each testcase, output a single line:
    • "Alice" if Alice wins with the optimal play.
    • "Bob" if Bob wins with the optimal play.
    • Otherwise, output "Tie".
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

In the first case:

  • Alice can choose the 3rd card, and Bob get the other two cards.
  • Then the power of Alice is 33=9, and the power of Bob is 1(1+2)=3.
  • Thus, Alice wins.

In the second case:

  • If Alice choose the 1st card, then the power of Alice and Bob are 13=3 and 2(2+1)=6, respectively. So Bob wins.
  • If Alice choose the 2nd card,  then the power of Alice and Bob are 22=4 and 1(1+3)=4, respectively. So they get a tie.
  • If Alice choose the 3rd card, then the power of Alice and Bob are 31=3 and 1(2+3)=5, respectively. So Bob wins.
  • Since Alice has the right to choose first, she would choose the 2nd card to get a tie.
Editor Image

?