CF1798F.Gifts from Grandfather Ahmed
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Grandfather Ahmed's School has n+1 students. The students are divided into k classes, and si students study in the i -th class. So, s1+s2+…+sk=n+1 .
Due to the upcoming April Fools' Day, all students will receive gifts!
Grandfather Ahmed planned to order n+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:
- Class number i receives exactly si boxes (so that each student can open exactly one box).
- The total number of gifts in the boxes received by the i -th class should be a multiple of si (it should be possible to equally distribute the gifts among the si students of this class).
Unfortunately, Grandfather Ahmed ordered only n boxes with gifts, the i -th of which contains ai gifts.
Ahmed has to buy the missing gift box, and the number of gifts in the box should be an integer between 1 and 106 . 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.
输入格式
The first line of the input contains two integers n and k ( 1≤n,k≤200 , k≤n+1 ).
The second line contains n integers a1,a2,…,an ( 1≤ai≤106 ) — the number of gifts in the available boxes.
The third line contains k integers s1,s2,…,sk ( 1≤si≤n+1 ) — the number of students in classes. It is guaranteed that ∑si=n+1 .
输出格式
If there is no way to buy the remaining box, output the integer −1 in a single line.
Otherwise, in the first line, output a single integer s — the number of gifts in the box that Grandfather Ahmed should buy ( 1≤s≤106 ).
Next, in k lines, print the distribution of boxes to classes. In the i -th line print si integers — the sizes of the boxes that should be sent to the i -th class.
If there are multiple solutions, print any of them.
输入输出样例
输入#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 1 gift. After that, two boxes with 7 gifts are sent to the first class. 7+7=14 is divisible by 2 . And the second class gets boxes with 1,7,127 gifts. 1+7+127=135 is evenly divisible by 3 .
In the second test, the classes have sizes 6 , 1 , 9 , and 3 . We show that the available boxes are enough to distribute into classes with sizes 6 , 9 , 3 , and in the class with size 1 , you can buy a box of any size. In class with size 6 we send boxes with sizes 7 , 1 , 7 , 6 , 5 , 4 . 7+1+7+6+5+4=30 is divisible by 6 . In class with size 9 we send boxes with sizes 1 , 2 , 3 , 8 , 3 , 2 , 9 , 8 , 9 . 1+2+3+8+3+2+9+8+9=45 is divisible by 9 . The remaining boxes ( 6 , 5 , 4 ) are sent to the class with size 3 . 6+5+4=15 is divisible by 3 .