P5412 [YNOI2019] Queueing

Description

Xiaoming’s class is going to hold an extracurricular activity. Before the activity starts, the teacher tells Xiaoming: “You need to split the girls and boys into two teams, and each team must be sorted by height from short to tall.” However, because Xiaoming was careless and did not pass the arrangement to his classmates, the whole class has already lined up in a single row. The activity is about to start, and Xiaoming’s teacher is troubled by this. Can you help her?

Input Format

Each input file contains multiple test cases. The first line of the input contains a positive integer $T$, which denotes the number of test cases in this input file. Then follow $T$ test cases. The format of each test case is as follows: Each test case consists of $3$ lines. The first line contains an integer $n$, representing the total number of students in the class, where $(0 < n \leq 2\times 10^{3})$. The second line contains $n$ integers separated by single spaces, representing the gender of each student in the already formed row. Each integer is either $0$ or $1$ ($0$ means girl, $1$ means boy). The third line contains $n$ floating-point numbers separated by single spaces, corresponding one-to-one with the second line, representing each student’s height $h(100 \leq h \leq 200)$ in the already formed row.

Output Format

The output file contains $2T$ lines, corresponding to the answers for the $T$ test cases. The format of each test case’s output is as follows: Each test case’s output consists of $2$ lines. The first line outputs the heights of all girls in increasing order. The second line outputs the heights of all boys in increasing order. Note that when outputting heights, please keep the same number of digits after the decimal point as in the original height.

Explanation/Hint

For $60\%$ of the testdata: $0 < n \leq 10^{2}$, $100 \leq h \leq 200$. For $80\%$ of the testdata: $0 < n \leq 10^{3}$, $100 \leq h \leq 200$. For $100\%$ of the testdata: $0 < n \leq 2\times 10^{3}$, $100 \leq h \leq 200$, $T\le 5$. Translated by ChatGPT 5