#7054. [NERC 2025] Battle of Arrays

[NERC 2025] Battle of Arrays

[NERC 2025] Battle of Arrays

题目描述

Alice and Bob play a turn-based game. Initially, Alice has an array $a$ of $n$ positive integers, and Bob has an array $b$ of $m$ positive integers. The players take turns, with Alice moving first.

On a player’s turn, they must choose one element xx from their own array and the maximal element yy from their opponent’s array. Then they perform the following operation:

  • If y≤xy \le x: the element yy is destroyed (removed from the opponent’s array).
  • If y>xy > x: the element yy is decreased by xx (the value of yy becomes y−xy - x).

A player wins if, after their move, the opponent’s array becomes empty.

Assuming both players play optimally, determine the winner.

输入格式

Each input contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$). The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$) — the sizes of Alice’s and Bob’s arrays respectively.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9) — Alice’s array.

The third line contains mm integers b1,b2,…,bmb_1, b_2, \dots, b_m (1≤bi≤1091 \le b_i \le 10^9) — Bob’s array.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5 and the sum of mm over all test cases does not exceed 10510^5.

输出格式

For each test case, print the name of the winner of the game if both players follow the optimal strategy: “Alice” or “Bob”.
2
1 1
70
90
2 3
30 30
20 20 40
Alice
Bob

提示

In the first test Alice moves and decreases Bob’s element by $70$, so it becomes $20$. Then Bob moves and decreases Alice’s element by $20$, so it becomes $50$. Finally, Alice moves, destroys Bob’s element, and wins. 标签: P14783|贪心|堆|2025|优先队列|ICPC|NERC/NEERC

来源

P14783|[NERC 2025] Battle of Arrays