A14593 | Weights
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an array $A$ of length $N$ weights of masses $A_1$ , $A_2$ ... $A_N$ . No two weights have the same mass. You can put every weight on one side of the balance (left or right). You don't have to put weights in order $A_1$ ,..., $A_N$ . There is also a string $S$ consisting of characters "L" and "R", meaning that after putting the $i-th$ weight (not $A_i$ , but $i-th$ weight of your choice) left or right side of the balance should be heavier. Find the order of putting the weights on the balance such that rules of string $S$ are satisfied.
输入格式
The first line contains one integer $N$ ( $1 \leq N \leq 2*10^5$ ) - the length of the array $A$ The second line contains $N$ distinct integers: $A_1$ , $A_2$ ,..., $A_N$ ( $1 \leq A_i \leq 10^9$ ) - the weights given The third line contains string $S$ of length $N$ consisting only of letters "L" and "R" - string determining which side of the balance should be heavier after putting the $i-th$ weight of your choice
输出格式
The output contains $N$ lines. In every line, you should print one integer and one letter - integer representing the weight you are putting on the balance in that move and the letter representing the side of the balance where you are putting the weight. If there is no solution, print $-1$ .
输入输出样例
输入 #1
5 3 8 2 13 7 LLRLL
输出 #1
3 L 2 R 8 R 13 L 7 L
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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted