English · Original
Chinese · Translation
Formal · Original
There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city.
Soon, monsters became hungry and began to eat each other.
One monster can eat other monster if its weight is **strictly greater** than the weight of the monster being eaten, and they stand in the queue next to each other. Monsters eat each other instantly. There are no monsters which are being eaten at the same moment. After the monster _A_ eats the monster _B_, the weight of the monster _A_ increases by the weight of the eaten monster _B_. In result of such eating the length of the queue decreases by one, all monsters after the eaten one step forward so that there is no empty places in the queue again. A monster can eat several monsters one after another. Initially there were _n_ monsters in the queue, the _i_\-th of which had weight _a__i_.
For example, if weights are \[1, 2, 2, 2, 1, 2\] (in order of queue, monsters are numbered from 1 to 6 from left to right) then some of the options are:
1. the first monster can't eat the second monster because _a_1 = 1 is not greater than _a_2 = 2;
2. the second monster can't eat the third monster because _a_2 = 2 is not greater than _a_3 = 2;
3. the second monster can't eat the fifth monster because they are not neighbors;
4. the second monster can eat the first monster, the queue will be transformed to \[3, 2, 2, 1, 2\].
After some time, someone said a good joke and all monsters recovered. At that moment there were _k_ (_k_ ≤ _n_) monsters in the queue, the _j_\-th of which had weight _b__j_. Both sequences (_a_ and _b_) contain the weights of the monsters in the order from the first to the last.
You are required to provide one of the possible orders of eating monsters which led to the current queue, or to determine that this could not happen. Assume that the doctor didn't make any appointments while monsters were eating each other.
## Input
The first line contains single integer _n_ (1 ≤ _n_ ≤ 500) — the number of monsters in the initial queue.
The second line contains _n_ integers _a_1, _a_2, ..., _a__n_ (1 ≤ _a__i_ ≤ 106) — the initial weights of the monsters.
The third line contains single integer _k_ (1 ≤ _k_ ≤ _n_) — the number of monsters in the queue after the joke.
The fourth line contains _k_ integers _b_1, _b_2, ..., _b__k_ (1 ≤ _b__j_ ≤ 5·108) — the weights of the monsters after the joke.
Monsters are listed in the order from the beginning of the queue to the end.
## Output
In case if no actions could lead to the final queue, print "NO" (without quotes) in the only line.
Otherwise print "YES" (without quotes) in the first line. In the next _n_ - _k_ lines print actions in the chronological order. In each line print _x_ — the index number of the monster in the current queue which eats and, separated by space, the symbol '_L_' if the monster which stays the _x_\-th in the queue eats the monster in front of him, or '_R_' if the monster which stays the _x_\-th in the queue eats the monster behind him. After each eating the queue is enumerated again.
When one monster eats another the queue decreases. If there are several answers, print any of them.
[samples]
## Note
In the first example, initially there were _n_ = 6 monsters, their weights are \[1, 2, 2, 2, 1, 2\] (in order of queue from the first monster to the last monster). The final queue should be \[5, 5\]. The following sequence of eatings leads to the final queue:
* the second monster eats the monster to the left (i.e. the first monster), queue becomes \[3, 2, 2, 1, 2\];
* the first monster (note, it was the second on the previous step) eats the monster to the right (i.e. the second monster), queue becomes \[5, 2, 1, 2\];
* the fourth monster eats the mosnter to the left (i.e. the third monster), queue becomes \[5, 2, 3\];
* the finally, the third monster eats the monster to the left (i.e. the second monster), queue becomes \[5, 5\].
Note that for each step the output contains numbers of the monsters in their current order in the queue.
在Monstropolis爆发了一次流行病,所有怪物都生病了。为了康复,所有怪物排成一队,依次预约城市里唯一的医生。
不久后,怪物们开始饥饿并互相吞噬。
如果一个怪物的重量*严格大于*它旁边怪物的重量,那么它可以吃掉那个怪物,且它们在队列中相邻。怪物会立即被吃掉。同一时刻没有怪物正在被吃。当怪物 #cf_span[A] 吃掉怪物 #cf_span[B] 后,怪物 #cf_span[A] 的重量增加被吃掉怪物 #cf_span[B] 的重量。吃掉后,队列长度减少一,所有在被吃怪物之后的怪物向前移动,使队列中不再有空位。一个怪物可以连续吃掉多个怪物。最初队列中有 #cf_span[n] 个怪物,第 #cf_span[i] 个怪物的重量为 #cf_span[ai]。
例如,如果重量为 #cf_span[[1, 2, 2, 2, 1, 2]](按队列顺序,怪物从左到右编号为 #cf_span[1] 到 #cf_span[6]),则可能的某些情况如下:
过了一段时间,有人讲了一个好笑的笑话,所有怪物都康复了。此时队列中剩下 #cf_span[k](#cf_span[k ≤ n])个怪物,第 #cf_span[j] 个怪物的重量为 #cf_span[bj]。两个序列(#cf_span[a] 和 #cf_span[b])都按从前往后的顺序列出了怪物的重量。
你需要提供一种可能导致当前队列的怪物吞噬顺序,或者判断这种情况不可能发生。假设在怪物互相吞噬期间,医生没有安排任何预约。
第一行包含一个整数 #cf_span[n](#cf_span[1 ≤ n ≤ 500])——初始队列中怪物的数量。
第二行包含 #cf_span[n] 个整数 #cf_span[a1, a2, ..., an](#cf_span[1 ≤ ai ≤ 106])——怪物的初始重量。
第三行包含一个整数 #cf_span[k](#cf_span[1 ≤ k ≤ n])——讲完笑话后队列中怪物的数量。
第四行包含 #cf_span[k] 个整数 #cf_span[b1, b2, ..., bk](#cf_span[1 ≤ bj ≤ 5·108])——讲完笑话后怪物的重量。
怪物按从队列开头到结尾的顺序列出。
如果没有任何操作能导致最终队列,请在唯一一行中输出 "NO"(不含引号)。
否则,第一行输出 "YES"(不含引号)。接下来的 #cf_span[n - k] 行按时间顺序输出操作。每行输出 #cf_span[x] —— 当前队列中正在吞噬的怪物的编号,空格后跟符号 '_L_'(表示该怪物吃掉它前面的怪物),或 '_R_'(表示该怪物吃掉它后面的怪物)。每次吞噬后,队列会重新编号。
当一个怪物吃掉另一个时,队列长度减少。如果有多个答案,输出任意一个即可。
在第一个例子中,最初有 #cf_span[n = 6] 个怪物,它们的重量为 #cf_span[[1, 2, 2, 2, 1, 2]](按队列从第一个到最后一个)。最终队列应为 #cf_span[[5, 5]]。以下吞噬序列可得到最终队列:
注意,每一步的输出都使用当前队列中的怪物编号。
## Input
第一行包含一个整数 #cf_span[n](#cf_span[1 ≤ n ≤ 500])——初始队列中怪物的数量。第二行包含 #cf_span[n] 个整数 #cf_span[a1, a2, ..., an](#cf_span[1 ≤ ai ≤ 106])——怪物的初始重量。第三行包含一个整数 #cf_span[k](#cf_span[1 ≤ k ≤ n])——讲完笑话后队列中怪物的数量。第四行包含 #cf_span[k] 个整数 #cf_span[b1, b2, ..., bk](#cf_span[1 ≤ bj ≤ 5·108])——讲完笑话后怪物的重量。怪物按从队列开头到结尾的顺序列出。
## Output
如果没有任何操作能导致最终队列,请在唯一一行中输出 "NO"(不含引号)。否则,第一行输出 "YES"(不含引号)。接下来的 #cf_span[n - k] 行按时间顺序输出操作。每行输出 #cf_span[x] —— 当前队列中正在吞噬的怪物的编号,空格后跟符号 '_L_'(表示该怪物吃掉它前面的怪物),或 '_R_'(表示该怪物吃掉它后面的怪物)。每次吞噬后,队列会重新编号。当一个怪物吃掉另一个时,队列长度减少。如果有多个答案,输出任意一个即可。
[samples]
## Note
在第一个例子中,最初有 #cf_span[n = 6] 个怪物,它们的重量为 #cf_span[[1, 2, 2, 2, 1, 2]](按队列从第一个到最后一个)。最终队列应为 #cf_span[[5, 5]]。以下吞噬序列可得到最终队列:第二个怪物吃掉它左边的怪物(即第一个怪物),队列变为 #cf_span[[3, 2, 2, 1, 2]];第一个怪物(注意,它在上一步是第二个)吃掉它右边的怪物(即第二个怪物),队列变为 #cf_span[[5, 2, 1, 2]];第四个怪物吃掉它左边的怪物(即第三个怪物),队列变为 #cf_span[[5, 2, 3]];最后,第三个怪物吃掉它左边的怪物(即第二个怪物),队列变为 #cf_span[[5, 5]]。注意,每一步的输出都使用当前队列中的怪物编号。
**Definitions**
Let $ n \in \mathbb{Z}^+ $ be the initial number of monsters.
Let $ A = (a_1, a_2, \dots, a_n) $ be the initial sequence of monster weights.
Let $ k \in \mathbb{Z}^+ $ with $ k \leq n $ be the final number of monsters.
Let $ B = (b_1, b_2, \dots, b_k) $ be the final sequence of monster weights.
**Constraints**
1. $ 1 \leq n \leq 500 $
2. $ 1 \leq a_i \leq 10^6 $ for all $ i \in \{1, \dots, n\} $
3. $ 1 \leq k \leq n $
4. $ 1 \leq b_j \leq 5 \cdot 10^8 $ for all $ j \in \{1, \dots, k\} $
5. Each $ b_j $ must be the sum of a contiguous subsequence of $ A $, and these subsequences form a partition of $ A $.
6. For each $ j \in \{1, \dots, k\} $, if $ b_j = \sum_{i \in I_j} a_i $ for some contiguous index set $ I_j $, then for any two consecutive elements $ a_p, a_q $ within the same $ I_j $, there exists a valid sequence of adjacent eatings such that the monster containing $ a_p $ eventually eats the monster containing $ a_q $ (or vice versa) with the weight condition: a monster can only eat an adjacent monster if its *current* weight is *strictly greater*.
**Objective**
Determine whether there exists a sequence of $ n - k $ eating operations transforming $ A $ into $ B $, where each operation is specified by:
- The *current index* $ x $ (1-based) of the eating monster in the current queue,
- A direction $ \texttt{L} $ or $ \texttt{R} $, indicating whether it eats the monster to its left or right.
If such a sequence exists, output:
- "YES"
- Followed by $ n - k $ lines, each containing $ x $ and $ \texttt{L} $ or $ \texttt{R} $
Otherwise, output:
- "NO"
API Response (JSON)
{
"problem": {
"name": "C. Epidemic in Monstropolis",
"description": {
"content": "There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city. Soon, monsters became hungry and bega",
"description_type": "Markdown"
},
"platform": "Codeforces",
"limit": {
"time_limit": 1000,
"memory_limit": 262144
},
"difficulty": "None",
"is_remote": true,
"is_sync": true,
"sync_url": null,
"sign": "CF733C"
},
"statements": [
{
"statement_type": "Markdown",
"content": "There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city.\n\nSoon, monsters became hungry and bega...",
"is_translate": false,
"language": "English"
},
{
"statement_type": "Markdown",
"content": "在Monstropolis爆发了一次流行病,所有怪物都生病了。为了康复,所有怪物排成一队,依次预约城市里唯一的医生。\n\n不久后,怪物们开始饥饿并互相吞噬。\n\n如果一个怪物的重量*严格大于*它旁边怪物的重量,那么它可以吃掉那个怪物,且它们在队列中相邻。怪物会立即被吃掉。同一时刻没有怪物正在被吃。当怪物 #cf_span[A] 吃掉怪物 #cf_span[B] 后,怪物 #cf_span[A] 的重量...",
"is_translate": true,
"language": "Chinese"
},
{
"statement_type": "Markdown",
"content": "**Definitions** \nLet $ n \\in \\mathbb{Z}^+ $ be the initial number of monsters. \nLet $ A = (a_1, a_2, \\dots, a_n) $ be the initial sequence of monster weights. \nLet $ k \\in \\mathbb{Z}^+ $ with $ k \\...",
"is_translate": false,
"language": "Formal"
}
]
}