CF1893D.Colorful Constructive
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have n colored cubes, the i -th cube has color ai .
You need to distribute all the cubes on shelves. There are a total of m shelves, the i -th shelf can hold si cubes. Also, s1+s2+…+sm=n .
Suppose on a shelf of size k there are cubes of colors c1,c2,…,ck , in this order. Then we define the colorfulness of the shelf as the minimum distance between two different cubes of the same color on the shelf. If all the cubes on the shelf have different colors, then the colorfulness is considered to be equal to the size of the shelf, that is, the number k .
More formally, the colorfulness of c1,c2,…,ck is defined as follows:
- If all the colors c1,c2,…,ck are different, the colorfulness is considered to be k .
- Otherwise, the colorfulness is considered to be the smallest integer x≥1 such that there exists an index i (1≤i≤k−x) such that ci=ci+x .
For each shelf, you are given the minimum required colorfulness, that is, you are given numbers d1,d2,…,dm , which mean that shelf i must have a colorfulness ≥di for all i .
Distribute the available cubes among the shelves to ensure the required colorfulness, or report that it is impossible.
输入格式
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers n,m (1≤m≤n≤2⋅105) — the number of cubes and the number of shelves to distribute them to.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤n) — the colors of the cubes.
The third line of each test case contains m integers s1,s2,…,sm (1≤si≤n) — the sizes of the shelves. It's guaranteed, that s1+…+sm=n .
The fourth line of each test case contains m integers d1,d2,…,dm (1≤di≤si) — the minimum required colorfulness of the shelves.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 .
输出格式
For each test case, if it is impossible to distribute the cubes on the shelves satisfying all the requirements, output a single number −1 . Otherwise, output m lines, where the i -th line should contain si numbers representing the colors of the cubes on the i -th shelf, in the appropriate order.
输入输出样例
输入#1
6 10 3 1 1 1 1 2 2 2 3 3 4 6 2 2 4 1 1 8 2 7 7 7 7 8 8 8 8 4 4 2 2 5 1 5 4 3 2 1 5 3 7 3 1 2 2 2 2 3 4 1 2 4 1 2 4 12 7 6 6 6 6 6 6 6 6 6 7 8 9 2 2 2 2 2 1 1 1 2 2 2 1 1 1 20 2 11 20 15 6 8 18 12 16 8 20 10 12 3 12 20 11 15 8 17 17 8 12 3 5
输出#1
1 3 4 2 1 3 1 1 2 2 8 7 8 7 8 7 8 7 2 4 5 3 1 -1 6 6 7 6 8 6 9 6 6 6 6 6 12 17 20 15 8 20 16 11 15 20 17 12 10 8 3 18 12 11 8 6