CF1342D.Multiple Testcases
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 mi (1≤mi≤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 c1 arrays of size greater than or equal to 1 (≥1), no more than c2 arrays of size greater than or equal to 2, …, no more than ck arrays of size greater than or equal to k. Also, c1≥c2≥⋯≥ck.
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.
因此,你决定在 Codeforces 上举办一场比赛。你已经准备好了题目:题面、参考解答、校验器、数据生成器、测试数据……突然,你的命题协调员要求你将最简单那道题的所有测试数据改为包含多个测试用例(testcase)的形式!
最初,该题的每个测试用例仅是一个数组。每个数组的最大长度为 k。为简化问题,数组的具体内容无关紧要。你共有 n 个测试用例——其中第 i 个测试用例是一个长度为 mi 的数组(1≤mi≤k)。
你的命题协调员要求你把所有这些数组分配到若干个新的测试用例中。每个新测试用例可包含多个数组;但需满足如下限制:
- 每个测试用例中,长度 ≥1 的数组至多有 c1 个;
- 长度 ≥2 的数组至多有 c2 个;
- ……
- 长度 ≥k 的数组至多有 ck 个。
此外,保证 c1≥c2≥⋯≥ck。
现在你的目标是构造新测试用例,使得:
- 所有原始数组恰好出现在一个测试用例中;
- 每个测试用例均满足上述限制条件;
- 测试用例总数尽可能少。
请输出所能达到的最少测试用例数目,以及每个测试用例中所含数组的长度。
输入格式
The first line contains two integers n and k (1≤n,k≤2⋅105) — the number of initial tests and the limit for the size of each array.
The second line contains n integers m1,m2,…,mn (1≤mi≤k) — the sizes of the arrays in the original tests.
The third line contains k integers c1,c2,…,ck (n≥c1≥c2≥⋯≥ck≥1); ci is the maximum number of arrays of size greater than or equal to i you can have in a single testcase.
第一行包含两个整数 n 和 k(1≤n,k≤2⋅105)—— 分别表示初始测试用例的数量以及每个数组的大小上限。
第二行包含 n 个整数 m1,m2,…,mn(1≤mi≤k)—— 表示原始测试用例中各数组的大小。
第三行包含 k 个整数 c1,c2,…,ck(满足 n≥c1≥c2≥⋯≥ck≥1);其中 ci 表示单个测试用例中大小不小于 i 的数组的最大允许数量。
输出格式
In the first line print a single integer ans (1≤ans≤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 a1 a2 … at (1≤t≤n) — the testcase includes t arrays, ai 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 ck≥1 (and therefore c1≥1).
If there are multiple answers, you can output any one of them.
第一行输出一个整数 ans(1≤ans≤n)—— 即你能达到的最少测试用例数目。
接下来的 ans 行,每行应描述一个测试用例,格式如下:
t a1 a2 … at(其中 1≤t≤n)—— 该测试用例包含 t 个数组,ai 表示该测试用例中第 i 个数组的大小。
初始的每个数组必须且仅出现在一个测试用例中。特别地,这意味着所有 ans 个测试用例中 t 的总和应等于 n。
注意:由于 ck≥1(因此 c1≥1),答案一定存在。
若存在多个合法答案,输出任意一个即可。
输入输出样例
输入#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.
在第一个例子中,无法将测试用例分配到少于 3 个测试集中。所给答案满足条件:每个测试集包含至多 4 个长度大于等于 1 的数组,且至多 1 个长度大于等于 2 的数组,以及至多 1 个长度大于等于 3 的数组。
注意,该测试存在多个合法答案。例如,测试集的大小为 [[2],[1,2],[3]] 同样是正确的。
然而,测试集大小为 [[1,2],[2,3]] 是不合法的,因为第二个测试集中包含 2 个长度大于等于 2 的数组。
请注意第三个与第四个例子之间的区别:在第三个例子中,你最多可在一个测试集中放入 5 个长度大于等于 1 的数组,因此可以将所有数组放入单个测试集中;而在第四个例子中,每个测试集最多只能包含 1 个数组。因此,每个数组都必须被分配到一个独立的测试集中。
输入解题思路,AI测评打分。不知道怎么写?