CF1599A Weights
题目描述
给你一个长度为 $N$ 的质量为 $A_1,A_2,\dots,A_N$ 的数组 $A$。每个数组中的值表示各个砝码的重量。
所有砝码的质量均不相同。你可以把每个砝码放在天平的一边(左边或右边)。
你不必按照 $A_1,\dots,A_N$ 的顺序放置砝码。还有一个由字符 $\texttt{L}$ 和 $\texttt{R}$ 组成的字符串 $S$,意思是在放完第 $i$ 个砝码(不是 $A_i$ ,而是选择第 $i$ 个砝码)后,天平的左边或右边应该更重。
找出在天平上放置砝码的顺序,以便满足字符串 $S$ 的规则。
输入格式
第一行包含一个整数 $N$($1\le N\le 2\times 10^5$)。
第二行包含 $N$ 个不同的整数,$A_1,A_2,\dots,A_N$($1\le A_i\le 10^9$)。
第三行包含长度为 $N$ 的 $S$ 字符串,仅由字母 $\texttt{L}$ 和 $\texttt{R}$ 组成。
输出格式
输出包含 $N$ 行。在每一行中,你应该打印一个整数和一个字母——整数代表你在那一步中放在天平上的重量,字母代表你放重量的天平的一边。如果没有解决方案,打印 $-1$。
说明/提示
Explanation for the test case:
after the 1st weight: 3 L (left side is heavier)
after the 2nd weight: 2 R (left side is heavier)
after the 3rd weight: 8 R (right side is heavier)
after the 4th weight: 13 L (left side is heavier)
after the 5th weight: 7 L (left side is heavier)
So, the rules given by string $ S $ are fulfilled and our order of putting the weights is correct.