Codeforces Round 1023 (Div. 2)
B
Apples in Boxes
Codeforces
1100
原题
← AC →
翻译中…

Tom and Jerry found some apples in the basement. They decided to play a game to get some apples.

翻译中…

There are $n$ boxes, and the $i$-th box has $a_i$ apples inside. Tom and Jerry take turns picking up apples. Tom goes first. On their turn, they have to do the following:

翻译中…
  • Choose a box $i$ ($1 \le i \le n$) with a positive number of apples, i.e. $a_i \gt 0$, and pick $1$ apple from this box. Note that this reduces $a_i$ by $1$.
  • If no valid box exists, the current player loses.
  • If after the move, $\max(a_1, a_2, \ldots, a_n) - \min(a_1, a_2, \ldots, a_n) \gt k$ holds, then the current player (who made the last move) also loses.
翻译中…

If both players play optimally, predict the winner of the game.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n,k$ ($2 \le n \le 10^5,1\le k \le 10^9$).

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

翻译中…

Output

翻译中…

For each test case, print "Tom" (without quotes) if Tom will win, or "Jerry" (without quotes) otherwise.

翻译中…

Note

翻译中…

Note that neither player is necessarily playing an optimal strategy in the following games, just to give you an idea of how the game is going.

翻译中…

In the first test case of the example, one possible situation is shown as follows.

翻译中…
  • Tom takes an apple from the first box. The array $a$ becomes $[1, 1, 2]$. Tom does not lose because $\max(1, 1, 2) - \min(1, 1, 2) = 1 \le k$.
  • Jerry takes an apple from the first box as well. The array $a$ becomes $[0, 1, 2]$. Jerry loses because $\max(0, 1, 2) - \min(0, 1, 2) = 2 \gt k$.
翻译中…

样例

Input #1
3
3 1
2 1 2
3 1
1 1 3
2 1
1 4
Output #1
Tom
Tom
Jerry
InputCopy OutputCopy
题目信息
题号
2107B
时间限制
1 s
内存限制
256 MB
标签
博弈论
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。