問題一覧 > 通常問題

No.511 Falling Block Game: The Warmth of Handiwork

レベル : / AI推定難易度 : 1650 / 実行時間制限 : 1ケース 4.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 36
作問者 : はむこ / テスター : りあん
お気に入りにしたユーザー ProblemId : 1292 / 自分の提出
問題文最終更新日: 2026-06-25 14:12:00
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 162 (順位表) の他の問題:

Problem Statement

A and B played the following falling block game by hand. This game uses a sheet of grid paper with width $w$ and infinite height.
A moves first. The players take turns alternately.

(1) The player of the $i$-th turn is given an $a_i \times b_i$ block, made up of $1 \times 1$ blocks gathered with $a_i$ horizontally and $b_i$ vertically. The player places it anywhere they like.
(2) Each $1\times 1$ block is moved down until the space below it is a block or the bottom row.
(3) Count the columns whose block height has newly reached the scoring line $h$ or higher. The player who placed the block gains points equal to the number of those columns.
(4) If the heights of all blocks are at or above the scoring line, the game ends. Otherwise, the turn passes to the other player and play returns to (1).
(5) The player with more points when the game ends wins.

However, A and B, who were running the game by hand, got confused and continued playing without noticing that the game had ended.
Of course, they do not know who won, either.


Fortunately, a log remains that says "the player of the $i$-th move placed an $a_i \times b_i$ block at $x_i$". When placing, the left end of the block is aligned with $x_i$.
You are given the moves $a_i, b_i, x_i (1 \le i \leq n)$ of A and B's game. Please tell them the result of the game.

Input

$n\ w\ h$
$a_1\ b_1\ x_1$
$\vdots$
$a_n\ b_n\ x_n$

$1 \leq n \leq 100000$
$1 \leq h \leq 10^{15}$
$1 \leq w \leq 100000$
$1 \leq a_i \leq w$
$1 \leq b_i \leq 10^9$
$1 \leq x_i \leq w - a_i + 1$

All input values are natural numbers.
It is guaranteed that the game has ended after the given moves are performed.

Output

Print "A" if A wins, "B" if B wins, and "DRAW" if it is a draw (the "" are for clarity). Print a newline at the end.

Sample

Sample 1
Input
1 3 2
3 2 1
Output
A


Sample 2
Input
2 3 2
3 1 1
3 1 1
Output
B


Sample 3
Input
3 3 2
1 2 1
1 2 2
1 2 3
Output
A


Sample 4
Input
2 2 2
1 2 1
1 2 2
Output
DRAW


Sample 5
Input
9 7 10
6 5 2
6 4 2
7 5 1
7 6 1
6 2 2
5 7 2
5 2 3
7 9 1
7 7 1
Output
A


The game should actually have ended on move 4, with A winning.
However, A and B are confused, so they keep placing blocks.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。