CF1599A.Weights

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array AA of length NN weights of masses A1A_1, A2A_2...ANA_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 A1A_1,...,ANA_N. There is also a string SS consisting of characters "L" and "R", meaning that after putting the i−thi-th weight (not AiA_i, but i−thi-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 SS are satisfied.

给你一个长度为 NN 的数组 AA,其中包含质量分别为 A1,A2,…,ANA_1, A_2, \dots, A_N 的砝码。任意两个砝码的质量均不相同。你可以将每个砝码放在天平的左侧或右侧(任选其一)。你不必按 A1,…,ANA_1, \dots, A_N 的顺序放置砝码。此外,还给出一个由字符 "L" 和 "R" 组成的字符串 SS,其含义是:在放置第 ii 个砝码(注意:此处的“第 ii 个”指你所选择的放置顺序中的第 ii 个砝码,而非数组中下标为 ii 的砝码 AiA_i)之后,天平的左侧或右侧应更重("L" 表示左侧更重,"R" 表示右侧更重)。请找出一种砝码的放置顺序,使得字符串 SS 所规定的规则全部满足。

输入格式

The first line contains one integer NN (1≤N≤2∗1051 \leq N \leq 2*10^5) - the length of the array AA The second line contains NN distinct integers: A1A_1, A2A_2,...,ANA_N (1≤Ai≤1091 \leq A_i \leq 10^9) - the weights given The third line contains string SS of length NN consisting only of letters "L" and "R" - string determining which side of the balance should be heavier after putting the i−thi-th weight of your choice

第一行包含一个整数 NN(1≤N≤2∗1051 \leq N \leq 2*10^5)——数组 AA 的长度。
第二行包含 NN 个互不相同的整数:A1A_1, A2A_2, ..., ANA_N(1≤Ai≤1091 \leq A_i \leq 10^9)——给定的重量。
第三行包含一个长度为 NN 的字符串 SS,该字符串仅由字母 "L" 和 "R" 组成——该字符串表示:在放置你选择的第 ii 个重量后,天平的哪一侧应更重。

输出格式

The output contains NN 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.

输出包含 NN 行。在每一行中,你应打印一个整数和一个字母:该整数表示你在该步操作中放置在天平上的砝码重量,该字母表示你将砝码放置在天平的哪一侧。若无解,则输出 −1-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 SS are fulfilled and our order of putting the weights is correct.

测试用例说明:

放置第 1 个砝码后:3 L(左侧较重)

放置第 2 个砝码后:2 R(左侧较重)

放置第 3 个砝码后:8 R(右侧较重)

放置第 4 个砝码后:13 L(左侧较重)

放置第 5 个砝码后:7 L(左侧较重)

因此,字符串 SS 所给出的规则均被满足,且我们放置砝码的顺序是正确的。

输入解题思路,AI测评打分。不知道怎么写?

首页