#P1878. 舞蹈课
舞蹈课
Description
There are people attending a dance class. Each person’s dance skill is represented by an integer. At the beginning of the class, they stand in a line from left to right. Whenever there is at least one adjacent opposite-gender pair in the line, the pair with the smallest difference in dance skill will leave the line to start dancing. If multiple pairs have the same minimal difference, the leftmost such pair leaves. After a pair leaves, the gap in the line is closed while preserving the original order (that is, if the line is ABCD, then after BC leaves, the line becomes AD). Here, “smallest difference” means the absolute difference of their skill values is minimal, i.e., minimize .
Your task is to simulate the process and determine the dancing pairs and their order.
Input Format
The first line contains a positive integer denoting the number of people in the line.
The second line contains characters B or G, where B denotes a boy and G denotes a girl.
The third line contains integers . All information is given in left-to-right order.
Output Format
The first line contains an integer denoting the total number of pairs that leave the line.
Then output lines, each containing two integers. Print the pairs in the order they start dancing; each line contains the indices of the two partners (numbered from to in the left-to-right input order). Print the smaller index first, then the larger.
4
BGBG
4 2 4 3
2
3 4
1 2
Hint
For of the testdata, .
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号