CF45C.Dancing Lessons
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill a__i. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, having the minimal difference in dancing skills start to dance. If there are several such couples, the one first from the left starts to dance. After a couple leaves to dance, the line closes again, i.e. as a result the line is always continuous. The difference in dancing skills is understood as the absolute value of difference of a__i variable. Your task is to find out what pairs and in what order will start dancing.
有 n 个人参加舞蹈课。每个人以其舞蹈技能 ai 表征。课程开始时,他们从左到右排成一列。只要队列中至少存在一对相邻的男生与女生,就重复执行以下过程:找出所有相邻的男-女组合中,舞蹈技能差值(即 ∣ai−aj∣)最小的一对;若存在多个这样的组合,则选择最靠左的一对开始跳舞。一对人离开队伍去跳舞后,队列会再次闭合(即队列始终保持连续)。你的任务是确定哪些人组成舞伴,以及他们开始跳舞的顺序。
输入格式
The first line contains an integer n (1 ≤ n ≤ 2·105) — the number of people. The next line contains n symbols B or G without spaces. B stands for a boy, G stands for a girl. The third line contains n space-separated integers a__i (1 ≤ a__i ≤ 107) — the dancing skill. People are specified from left to right in the order in which they lined up.
第一行包含一个整数 n(1 ≤ n ≤ 2⋅105)—— 人数。
第二行包含 n 个字符,每个字符为 B 或 G,中间无空格。B 表示男孩,G 表示女孩。
第三行包含 n 个用空格分隔的整数 ai(1 ≤ ai ≤ 107)—— 舞蹈技能值。
人员按从左到右的队列顺序给出。
输出格式
Print the resulting number of couples k. Then print k lines containing two numerals each — the numbers of people forming the couple. The people are numbered with integers from 1 to n from left to right. When a couple leaves to dance you shouldn't renumber the people. The numbers in one couple should be sorted in the increasing order. Print the couples in the order in which they leave to dance.
输出最终的配对数 k。然后输出 k 行,每行包含两个数字——组成该配对的两个人的编号。所有人从左到右依次用整数 1 到 n 编号。当一对人离开去跳舞时,其余人的编号保持不变(不重新编号)。每对中两个数字应按升序排列。配对需按他们离开去跳舞的顺序输出。
输入输出样例
输入#1
4 BGBG 4 2 4 3
输出#1
2 3 4 1 2
输入#2
4 BBGG 4 6 1 5
输出#2
2 2 3 1 4
输入#3
4 BGBB 1 1 2 3
输出#3
1 1 2
输入解题思路,AI测评打分。不知道怎么写?