CF1242C.Sum Balance
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers.
There are k boxes numbered from 1 to k. The i-th box contains ni integer numbers. The integers can be negative. All of the integers are distinct.
Ujan is lazy, so he will do the following reordering of the numbers exactly once. He will pick a single integer from each of the boxes, k integers in total. Then he will insert the chosen numbers — one integer in each of the boxes, so that the number of integers in each box is the same as in the beginning. Note that he may also insert an integer he picked from a box back into the same box.
Ujan will be happy if the sum of the integers in each box is the same. Can he achieve this and make the boxes perfectly balanced, like all things should be?
乌詹的盒子里装着许多数字。他喜欢秩序与平衡,因此决定对这些数字重新排序。
共有 k 个盒子,编号从 1 到 k。第 i 个盒子中包含 ni 个整数。这些整数可以为负数,且所有整数互不相同。
乌詹比较懒,因此他只会执行一次如下重排操作:从每个盒子中各选出一个整数,共选出 k 个整数;然后将这 k 个选出的整数——每个整数插入一个盒子(每个盒子恰好插入一个整数),使得每个盒子中整数的个数与初始时相同。注意:他也可以将从某个盒子中选出的整数再放回同一个盒子中。
如果每个盒子中整数的和都相等,乌詹就会感到开心。他能否实现这一目标,使所有盒子达到完美的平衡状态(就像世间万物本应如此一样)?
输入格式
The first line contains a single integer k (1≤k≤15), the number of boxes.
The i-th of the next k lines first contains a single integer ni (1≤ni≤5000), the number of integers in box i. Then the same line contains ni integers ai,1,…,ai,ni (∣ai,j∣≤109), the integers in the i-th box.
It is guaranteed that all ai,j are distinct.
第一行包含一个整数 k(1≤k≤15),表示盒子的数量。
接下来的 k 行中,第 i 行首先包含一个整数 ni(1≤ni≤5000),表示第 i 个盒子中的整数个数;随后在同一行中给出 ni 个整数 ai,1,…,ai,ni(∣ai,j∣≤109),即第 i 个盒子中的所有整数。
保证所有 ai,j 互不相同。
输出格式
If Ujan cannot achieve his goal, output "No" in a single line. Otherwise in the first line output "Yes", and then output k lines. The i-th of these lines should contain two integers ci and pi. This means that Ujan should pick the integer ci from the i-th box and place it in the pi-th box afterwards.
If there are multiple solutions, output any of those.
You can print each letter in any case (upper or lower).
如果乌詹无法实现他的目标,则在单独一行中输出“No”。否则,在第一行输出“Yes”,然后输出 k 行。其中第 i 行应包含两个整数 ci 和 pi,表示乌詹应从第 i 个盒子中取出整数 ci,并将其放入第 pi 个盒子中。
若存在多种解法,输出任意一种即可。
字母大小写均可(即可以大写或小写)。
输入输出样例
输入#1
4 3 1 7 4 2 3 2 2 8 5 1 10
输出#1
Yes 7 2 2 3 5 1 10 4
输入#2
2 2 3 -2 2 -1 5
输出#2
No
输入#3
2 2 -10 10 2 0 -20
输出#3
Yes -10 2 -20 1
说明/提示
In the first sample, Ujan can put the number 7 in the 2nd box, the number 2 in the 3rd box, the number 5 in the 1st box and keep the number 10 in the same 4th box. Then the boxes will contain numbers 1,5,4, 3,7, 8,2 and 10. The sum in each box then is equal to 10.
In the second sample, it is not possible to pick and redistribute the numbers in the required way.
In the third sample, one can swap the numbers −20 and −10, making the sum in each box equal to −10.
在第一个样例中,Ujan 可以将数字 7 放入第 2 个盒子,将数字 2 放入第 3 个盒子,将数字 5 放入第 1 个盒子,并将数字 10 保留在第 4 个盒子中。此时各盒子中的数字分别为 {1,5,4}、{3,7}、{8,2} 和 {10}。每个盒子中的数字之和均为 10。
在第二个样例中,无法按要求选取并重新分配这些数字。
在第三个样例中,可以交换数字 −20 和 −10,使得每个盒子中的数字之和均为 −10。
输入解题思路,AI测评打分。不知道怎么写?