#P14217. [ICPC 2024 Kunming I] 两星级竞赛
[ICPC 2024 Kunming I] 两星级竞赛
Problem Description
For some reason, education experts are going to rate contests. The experts have already decided the rating of each contest, where the -th contest is rated as an -star contest.
It is said that each contest is rated according to attributes, where the -th attribute of the -th contest is denoted by , and each attribute takes a value from to (inclusive). The score of a contest is the sum of all its attributes. That is, letting denote the score of the -th contest, we have .
It looks more natural if a contest with more stars has a higher score. The experts require that for any two contests , if , then must hold. Unfortunately, the experts forgot to collect the data of some (or even all) attributes of some contests. As the assistant of the experts, you are asked to fill in these missing attribute values so that the above restriction holds for any two contests.
Input Format
There are multiple test cases. The first line contains an integer denoting the number of test cases. For each test case:
The first line contains three integers , and (, , , ) denoting the number of contests, how many attributes each contest has, and the upper bound of the value of each attribute.
For the next lines, the -th line first contains an integer () denoting the star rating of the -th contest. Then integers () follow. If , the value of the -th attribute of the -th contest is missing and you need to fill it in; otherwise, if , the value of the -th attribute of the -th contest is given and you should not change it.
It is guaranteed that the sum of over all test cases does not exceed .
Output Format
For each test case:
If it is possible to fill in all missing attribute values and satisfy the restriction, first output one line with . Then output lines, where the -th line contains integers () separated by single spaces, denoting the attribute values of the -th contest after filling. If , then is the value you filled in; otherwise, if , then . If there are multiple answers, you may output any of them.
If the restriction cannot be satisfied, just output one line with .
5
3 4 5
5 1 3 -1 -1
2 -1 5 -1 5
3 3 -1 -1 4
2 3 10
10000 5 0 -1
1 10 10 10
2 3 10
10 1 2 3
100 4 5 6
2 3 10
100 1 2 3
10 4 5 6
2 3 10000
100 -1 -1 -1
1 -1 -1 -1
Yes
1 3 5 4
0 5 0 5
3 3 2 4
No
Yes
1 2 3
4 5 6
No
Yes
2024 5 26
11 45 14
Hint
For the second sample, even if we fill the only with the maximum possible value , the score of the first contest is only , which is not greater than the score of the second contest.
Translated by QwenWork