#P14024. [ICPC 2024 Nanjing R] 纸条
[ICPC 2024 Nanjing R] 纸条
Description
There are cells arranged in a row, numbered from to from left to right. Among the cells, of them are red, of them are black, and the remaining cells are white.
You need to cover all the red cells with some strips. Each strip must cover continuous cells. Find a way to cover all red cells while satisfying all the following constraints:
- Each red cell is covered by a strip.
- No black cell is covered by a strip.
- No two strips cover the same cell. That is, each cell is covered by at most one strip.
- The number of strips used is as small as possible.
Input Format
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:
The first line contains four integers , , and (, , ), indicating the number of red cells, the number of black cells, the length of each strip and the total number of cells.
The second line contains integers (), indicating that cell is red.
The third line contains integers (), indicating that cell is black.
It's guaranteed that the given cells are distinct. It's also guaranteed that neither the sum of nor the sum of of all test cases will exceed .
Output Format
For each test case:
If it is possible to cover all the red cells while satisfying all constraints, first output one line containing one integer indicating the smallest number of strips used. Then output another line containing integers () separated by a space, where is the left-most cell covered by the -th strip. If there are multiple valid answers, you can output any of them.
If it is not possible to do so, just output in one line.
4
5 2 3 16
7 11 2 9 14
13 5
3 2 4 11
6 10 2
1 11
2 1 2 6
1 5
3
2 1 2 6
1 5
2
4
6 2 14 9
-1
2
1 4
-1
京公网安备 11011102002149号