CF1342D.Multiple Testcases

普及/提高-

通过率:0%

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 kk . For simplicity, the contents of arrays don't matter. You have nn tests — the ii -th test is an array of size mim_i ( 1mik1 \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 c1c_1 arrays of size greater than or equal to 11 ( 1\ge 1 ), no more than c2c_2 arrays of size greater than or equal to 22 , \dots , no more than ckc_k arrays of size greater than or equal to kk . Also, c1c2ckc_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 nn and kk ( 1n,k21051 \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 nn integers m1,m2,,mnm_1, m_2, \dots, m_n ( 1mik1 \le m_i \le k ) — the sizes of the arrays in the original tests.

The third line contains kk integers c1,c2,,ckc_1, c_2, \dots, c_k ( nc1c2ck1n \ge c_1 \ge c_2 \ge \dots \ge c_k \ge 1 ); cic_i is the maximum number of arrays of size greater than or equal to ii you can have in a single testcase.

输出格式

In the first line print a single integer ansans ( 1ansn1 \le ans \le n ) — the minimum number of testcases you can achieve.

Each of the next ansans lines should contain the description of a testcase in the following format:

tt a1a_1 a2a_2 \dots ata_{t} ( 1tn1 \le t\le n ) — the testcase includes tt arrays, aia_i is the size of the ii -th array in that testcase.

Each of the initial arrays should appear in exactly one testcase. In particular, it implies that the sum of tt over all ansans testcases should be equal to nn .

Note that the answer always exists due to ck1c_k \ge 1 (and therefore c11c_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 33 testcases. The given answer satisfies the conditions: each of the testcases includes no more than 44 arrays of size greater than or equal to 11 and no more than 11 array of sizes greater than or equal to 22 and 33 .

Note that there are multiple valid answers for this test. For example, testcases with sizes [[2],[1,2],[3]][[2], [1, 2], [3]] would also be correct.

However, testcases with sizes [[1,2],[2,3]][[1, 2], [2, 3]] would be incorrect because there are 22 arrays of size greater than or equal to 22 in the second testcase.

Note the difference between the third and the fourth examples. You can include up to 55 arrays of size greater than or equal to 11 in the third example, so you can put all arrays into a single testcase. And you can have only up to 11 array in the fourth example. Thus, every array should be included in a separate testcase.

首页