QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 2048 MB Puntuación total: 100

#3864. 瓶子排列

Estadísticas

Gabriella 受命组织一场著名的品酒活动,将有 $m$ 位评论家参加。现场将展示 $n$ 种不同的葡萄酒,每种酒可以是红葡萄酒或白葡萄酒。

这些酒将以 $n$ 个瓶子的形式排成一行放在桌子上。为了方便起见,每位评论家将从一个连续的瓶子区间中品尝:也就是说,他/她将品尝位置在 $a, a+1, \dots, b$ 的瓶子,其中 $1 \le a \le b \le n$。区间取决于评论家,他们会根据自己的喜好当场选择。事实上,第 $i$ 位评论家($1 \le i \le m$)要求他/她想要品尝恰好 $r_i$ 瓶红葡萄酒和 $w_i$ 瓶白葡萄酒。

Gabriella 尚未决定红葡萄酒和白葡萄酒的数量,以及它们出现的顺序。请帮助她找到一种排列方式(即一个由 $n$ 个红葡萄酒或白葡萄酒瓶组成的序列),满足所有评论家的要求,或者指出不存在这样的排列。

输入格式

每个测试包含多个测试用例。第一行包含一个整数 $t$ ($1 \le t \le 100$),表示测试用例的数量。接下来是 $t$ 个测试用例的描述。

每个测试用例的第一行包含两个整数 $n$ 和 $m$ ($1 \le n \le 100, 1 \le m \le 100$),分别表示酒瓶的数量和评论家的数量。

接下来的 $m$ 行中,每行包含两个整数 $r_i$ 和 $w_i$ ($0 \le r_i, w_i \le 100, r_i + w_i \ge 1$),表示第 $i$ 位评论家想要品尝的红葡萄酒和白葡萄酒的数量。

输出格式

对于每个测试用例,如果至少存在一个解,请打印一个长度为 $n$ 的字符串,由字符 RW 组成,其中第 $j$ 个字符($1 \le j \le n$)表示排列中第 $j$ 个瓶子的酒的类型(R 代表红葡萄酒,W 代表白葡萄酒)。如果存在多个解,打印任意一个即可。

如果不存在解,请打印字符串 IMPOSSIBLE

样例

样例输入 1

3
5 3
1 0
3 2
2 2
4 3
2 1
1 1
0 3
3 2
0 2
0 3

样例输出 1

RWRRW
IMPOSSIBLE
WWW

说明

在第一个测试用例中,有 $n=5$ 瓶酒需要排列,有 $m=3$ 位评论家。排列 RWRRW 满足所有三位评论家的要求。事实上:

  • 第一位评论家可以选择区间 $[3, 3]$,其中恰好包含一瓶红葡萄酒(注意 $[1, 1]$ 和 $[4, 4]$ 也是其他有效的选择);
  • 第二位评论家可以选择区间 $[1, 5]$,其中包含 3 瓶红葡萄酒和 2 瓶白葡萄酒;
  • 第三位评论家可以选择区间 $[2, 5]$,其中包含 2 瓶红葡萄酒和 2 瓶白葡萄酒。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.