CF1798F.Gifts from Grandfather Ahmed

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Grandfather Ahmed's School has n+1n+1 students. The students are divided into kk classes, and sis_i students study in the ii-th class. So, s1+s2+…+sk=n+1s_1 + s_2 + \ldots + s_k = n+1.

Due to the upcoming April Fools' Day, all students will receive gifts!

Grandfather Ahmed planned to order n+1n+1 boxes of gifts. Each box can contain one or more gifts. He plans to distribute the boxes between classes so that the following conditions are satisfied:

  1. Class number ii receives exactly sis_i boxes (so that each student can open exactly one box).
  2. The total number of gifts in the boxes received by the ii-th class should be a multiple of sis_i (it should be possible to equally distribute the gifts among the sis_i students of this class).

Unfortunately, Grandfather Ahmed ordered only nn boxes with gifts, the ii-th of which contains aia_i gifts.

Ahmed has to buy the missing gift box, and the number of gifts in the box should be an integer between 11 and 10610^6. Help Ahmed to determine, how many gifts should the missing box contain, and build a suitable distribution of boxes to classes, or report that this is impossible.

艾哈迈德爷爷的学校共有 n+1n+1 名学生。这些学生被分入 kk 个班级,其中第 ii 个班级有 sis_i 名学生。因此,满足 s1+s2+…+sk=n+1s_1 + s_2 + \ldots + s_k = n+1。

由于即将到来的愚人节,所有学生都将收到礼物!

艾哈迈德爷爷原计划订购 n+1n+1 个礼物盒。每个盒子可装一个或多个礼物。他打算将这些盒子分配给各个班级,使得满足以下条件:

  1. 第 ii 个班级恰好收到 sis_i 个盒子(从而保证每名学生恰好打开一个盒子);
  2. 第 ii 个班级所收到的所有盒子中的礼物总数必须是 sis_i 的倍数(即这些礼物可以被该班的 sis_i 名学生平均分配)。

不幸的是,艾哈迈德爷爷只订购了 nn 个装有礼物的盒子,其中第 ii 个盒子含有 aia_i 个礼物。

艾哈迈德必须购买缺失的那个礼物盒,且该盒中礼物数量必须为介于 11 到 10610^6 之间的整数。请帮助艾哈迈德确定:缺失的盒子中应装多少个礼物,并构造一种满足上述条件的盒子到班级的分配方案;若不可能实现,请报告这一点。

输入格式

The first line of the input contains two integers nn and kk (1≤n,k≤2001 \le n, k \le 200, k≤n+1k \le n + 1).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1061 \le a_i \le 10^6) — the number of gifts in the available boxes.

The third line contains kk integers s1,s2,…,sks_1, s_2, \ldots, s_k (1≤si≤n+11 \le s_i \le n+1) — the number of students in classes. It is guaranteed that ∑si=n+1\sum s_i = n+1.

输入的第一行包含两个整数 nn 和 kk(1≤n,k≤2001 \le n, k \le 200,且 k≤n+1k \le n + 1)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1061 \le a_i \le 10^6)——表示可用盒子中礼物的数量。

第三行包含 kk 个整数 s1,s2,…,sks_1, s_2, \ldots, s_k(1≤si≤n+11 \le s_i \le n+1)——表示各班级的学生人数。保证 ∑si=n+1\sum s_i = n+1。

输出格式

If there is no way to buy the remaining box, output the integer −1-1 in a single line.

Otherwise, in the first line, output a single integer ss — the number of gifts in the box that Grandfather Ahmed should buy (1≤s≤1061 \le s \le 10^6).

Next, in kk lines, print the distribution of boxes to classes. In the ii-th line print sis_i integers — the sizes of the boxes that should be sent to the ii-th class.

If there are multiple solutions, print any of them.

如果无法购买剩余的盒子,则在单独一行中输出整数 −1-1。

否则,在第一行输出一个整数 ss —— 祖父艾哈迈德应购买的盒子中的礼物数量(1≤s≤1061 \le s \le 10^6)。

接下来,在 kk 行中,输出盒子分配给各班级的方案。在第 ii 行输出 sis_i 个整数 —— 应发送给第 ii 个班级的盒子的尺寸。

若存在多种解法,输出任意一种即可。

输入输出样例

  • 输入#1

    4 2
    7 7 7 127
    2 3

    输出#1

    1
    7 7 
    7 127 1
  • 输入#2

    18 4
    1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
    6 1 9 3

    输出#2

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

说明/提示

In the first test, Grandfather Ahmed can buy a box with just 11 gift. After that, two boxes with 77 gifts are sent to the first class. 7+7=147 + 7 = 14 is divisible by 22. And the second class gets boxes with 1,7,1271, 7, 127 gifts. 1+7+127=1351 + 7 + 127 = 135 is evenly divisible by 33.

In the second test, the classes have sizes 66, 11, 99, and 33. We show that the available boxes are enough to distribute into classes with sizes 66, 99, 33, and in the class with size 11, you can buy a box of any size. In class with size 66 we send boxes with sizes 77, 11, 77, 66, 55, 44. 7+1+7+6+5+4=307 + 1 + 7 + 6 + 5 + 4 = 30 is divisible by 66. In class with size 99 we send boxes with sizes 11, 22, 33, 88, 33, 22, 99, 88, 99. 1+2+3+8+3+2+9+8+9=451 + 2 + 3 + 8 + 3 + 2 + 9 + 8 + 9 = 45 is divisible by 99. The remaining boxes (66, 55, 44) are sent to the class with size 33. 6+5+4=156 + 5 + 4 = 15 is divisible by 33.

在第一个测试用例中,祖父艾哈迈德可以购买一个仅含 11 件礼物的盒子。随后,向第一个班级发送两个各含 77 件礼物的盒子,7+7=147 + 7 = 14 可被 22 整除。第二个班级则收到含 11、77、127127 件礼物的盒子,1+7+127=1351 + 7 + 127 = 135 可被 33 整除。

在第二个测试用例中,各班级人数分别为 66、11、99 和 33。我们说明:现有盒子足以分配给大小为 66、99、33 的班级;而对于人数为 11 的班级,可购买任意大小的盒子。在人数为 66 的班级中,我们发送大小分别为 77、11、77、66、55、44 的盒子,其总和 7+1+7+6+5+4=307 + 1 + 7 + 6 + 5 + 4 = 30 可被 66 整除。在人数为 99 的班级中,我们发送大小分别为 11、22、33、88、33、22、99、88、99 的盒子,其总和 1+2+3+8+3+2+9+8+9=451 + 2 + 3 + 8 + 3 + 2 + 9 + 8 + 9 = 45 可被 99 整除。剩余的盒子(大小为 66、55、44)发送至人数为 33 的班级,其总和 6+5+4=156 + 5 + 4 = 15 可被 33 整除。

输入解题思路,AI测评打分。不知道怎么写?

首页