307342: CF1342D. Multiple Testcases

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Multiple Testcases

题意翻译

给予$n$个整数$m_{1,2,...,n}$,现在要将它们放进若干容器,要求: - 在每个容器$p_j$中,对于每个数$i$($1 \le i \le k$),大于等于$i$的数不能超过$c_i$个。 求最小所需容器数以及安排方式,保证: - $1 \le n \le 2 \cdot 10^5$ - $1 \le k \le 2 \cdot 10^5$ - $1 \le m_i \le k$ - $n \ge c_1 \ge c_2 \ge ...\ge c_k \ge 1$ 输入格式: - 第一行两个整数$n,k$。 - 第二行$n$个整数$m_{1,2,...,n}$。 - 第三行$k$个整数$c_{1,2,...,k}$。 输出格式: - 第一行输出最小容器数$ans$($1 \le ans \le n$)。 - 接下来输出$ans$行,第$i$行先输出一个整数$t$($1 \le t \le n$),接下来输出$t$个整数,表示第$i-1$个容器中的元素。 - $\sum t = n$。 - $m$中的每个数恰好在某个容器中出现一次。 - 输出任意一组最优解即可。 因为$c_k \ge 1$,所以一定存在一种合法分配方式。

题目描述

So you decided to hold a contest on Codeforces. You prepared the problems: statements, solutions, checkers, validators, tests... Suddenly, your coordinator asks you to change all your tests to multiple testcases in the easiest problem! Initially, each test in that problem is just an array. The maximum size of an array is $ k $ . For simplicity, the contents of arrays don't matter. You have $ n $ tests — the $ i $ -th test is an array of size $ m_i $ ( $ 1 \le m_i \le k $ ). Your coordinator asks you to distribute all of your arrays into multiple testcases. Each testcase can include multiple arrays. However, each testcase should include no more than $ c_1 $ arrays of size greater than or equal to $ 1 $ ( $ \ge 1 $ ), no more than $ c_2 $ arrays of size greater than or equal to $ 2 $ , $ \dots $ , no more than $ c_k $ arrays of size greater than or equal to $ k $ . Also, $ c_1 \ge c_2 \ge \dots \ge c_k $ . So now your goal is to create the new testcases in such a way that: - each of the initial arrays appears in exactly one testcase; - for each testcase the given conditions hold; - the number of testcases is minimum possible. Print the minimum possible number of testcases you can achieve and the sizes of arrays included in each testcase.

输入输出格式

输入格式


The first line contains two integers $ n $ and $ k $ ( $ 1 \le n, k \le 2 \cdot 10^5 $ ) — the number of initial tests and the limit for the size of each array. The second line contains $ n $ integers $ m_1, m_2, \dots, m_n $ ( $ 1 \le m_i \le k $ ) — the sizes of the arrays in the original tests. The third line contains $ k $ integers $ c_1, c_2, \dots, c_k $ ( $ n \ge c_1 \ge c_2 \ge \dots \ge c_k \ge 1 $ ); $ c_i $ is the maximum number of arrays of size greater than or equal to $ i $ you can have in a single testcase.

输出格式


In the first line print a single integer $ ans $ ( $ 1 \le ans \le n $ ) — the minimum number of testcases you can achieve. Each of the next $ ans $ lines should contain the description of a testcase in the following format: $ t $ $ a_1 $ $ a_2 $ $ \dots $ $ a_{t} $ ( $ 1 \le t\le n $ ) — the testcase includes $ t $ arrays, $ a_i $ is the size of the $ i $ -th array in that testcase. Each of the initial arrays should appear in exactly one testcase. In particular, it implies that the sum of $ t $ over all $ ans $ testcases should be equal to $ n $ . Note that the answer always exists due to $ c_k \ge 1 $ (and therefore $ c_1 \ge 1 $ ). If there are multiple answers, you can output any one of them.

输入输出样例

输入样例 #1

4 3
1 2 2 3
4 1 1

输出样例 #1

3
1 2
2 1 3
1 2

输入样例 #2

6 10
5 8 1 10 8 7
6 6 4 4 3 2 2 2 1 1

输出样例 #2

2
3 8 5 7
3 10 8 1

输入样例 #3

5 1
1 1 1 1 1
5

输出样例 #3

1
5 1 1 1 1 1

输入样例 #4

5 1
1 1 1 1 1
1

输出样例 #4

5
1 1
1 1
1 1
1 1
1 1

说明

In the first example there is no way to distribute the tests into less than $ 3 $ testcases. The given answer satisfies the conditions: each of the testcases includes no more than $ 4 $ arrays of size greater than or equal to $ 1 $ and no more than $ 1 $ array of sizes greater than or equal to $ 2 $ and $ 3 $ . Note that there are multiple valid answers for this test. For example, testcases with sizes $ [[2], [1, 2], [3]] $ would also be correct. However, testcases with sizes $ [[1, 2], [2, 3]] $ would be incorrect because there are $ 2 $ arrays of size greater than or equal to $ 2 $ in the second testcase. Note the difference between the third and the fourth examples. You can include up to $ 5 $ arrays of size greater than or equal to $ 1 $ in the third example, so you can put all arrays into a single testcase. And you can have only up to $ 1 $ array in the fourth example. Thus, every array should be included in a separate testcase.

Input

题意翻译

给予$n$个整数$m_{1,2,...,n}$,现在要将它们放进若干容器,要求: - 在每个容器$p_j$中,对于每个数$i$($1 \le i \le k$),大于等于$i$的数不能超过$c_i$个。 求最小所需容器数以及安排方式,保证: - $1 \le n \le 2 \cdot 10^5$ - $1 \le k \le 2 \cdot 10^5$ - $1 \le m_i \le k$ - $n \ge c_1 \ge c_2 \ge ...\ge c_k \ge 1$ 输入格式: - 第一行两个整数$n,k$。 - 第二行$n$个整数$m_{1,2,...,n}$。 - 第三行$k$个整数$c_{1,2,...,k}$。 输出格式: - 第一行输出最小容器数$ans$($1 \le ans \le n$)。 - 接下来输出$ans$行,第$i$行先输出一个整数$t$($1 \le t \le n$),接下来输出$t$个整数,表示第$i-1$个容器中的元素。 - $\sum t = n$。 - $m$中的每个数恰好在某个容器中出现一次。 - 输出任意一组最优解即可。 因为$c_k \ge 1$,所以一定存在一种合法分配方式。

加入题单

算法标签: