#P5412. [YNOI2019] 排队

[YNOI2019] 排队

Problem 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 TT, which denotes the number of test cases in this input file.

Then follow TT test cases. The format of each test case is as follows:

Each test case consists of 33 lines.

The first line contains an integer nn, representing the total number of students in the class, where (0<n2×103)(0 < n \leq 2\times 10^{3}).

The second line contains nn integers separated by single spaces, representing the gender of each student in the already formed row. Each integer is either 00 or 11 (00 means girl, 11 means boy).

The third line contains nn floating-point numbers separated by single spaces, corresponding one-to-one with the second line, representing each student’s height h(100h200)h(100 \leq h \leq 200) in the already formed row.

Output Format

The output file contains 2T2T lines, corresponding to the answers for the TT test cases. The format of each test case’s output is as follows:

Each test case’s output consists of 22 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.

1
5
1 0 1 0 1
120.2 130.3 140.4 150.5 160.6

130.3 150.5
120.2 140.4 160.6

Hint

For 60%60\% of the testdata: 0<n1020 < n \leq 10^{2}, 100h200100 \leq h \leq 200.

For 80%80\% of the testdata: 0<n1030 < n \leq 10^{3}, 100h200100 \leq h \leq 200.

For 100%100\% of the testdata: 0<n2×1030 < n \leq 2\times 10^{3}, 100h200100 \leq h \leq 200, T5T\le 5.

Translated by ChatGPT 5