CF509B.Painting Pebbles
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n piles of pebbles on the table, the i-th pile contains a__i pebbles. Your task is to paint each pebble using one of the k given colors so that for each color c and any two piles i and j the difference between the number of pebbles of color c in pile i and number of pebbles of color c in pile j is at most one.
In other words, let's say that b__i, c is the number of pebbles of color c in the i-th pile. Then for any 1 ≤ c ≤ k, 1 ≤ i, j ≤ n the following condition must be satisfied |b__i, c - b__j, c| ≤ 1. It isn't necessary to use all k colors: if color c hasn't been used in pile i, then b__i, c is considered to be zero.
桌上有 n 堆石子,第 i 堆包含 ai 颗石子。你的任务是用给定的 k 种颜色之一为每颗石子染色,使得对任意颜色 c 以及任意两堆石子 i 和 j,第 i 堆中颜色为 c 的石子数与第 j 堆中颜色为 c 的石子数之差的绝对值至多为 1。
换言之,设 bi,c 表示第 i 堆中颜色为 c 的石子数量,则对任意 1≤c≤k、1≤i,j≤n,必须满足 ∣bi,c−bj,c∣≤1。不必使用全部 k 种颜色:若颜色 c 在第 i 堆中未被使用,则视 bi,c=0。
输入格式
The first line of the input contains positive integers n and k (1 ≤ n, k ≤ 100), separated by a space — the number of piles and the number of colors respectively.
The second line contains n positive integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 100) denoting number of pebbles in each of the piles.
输入的第一行包含两个正整数 n 和 k(1 ≤ n, k ≤ 100),以空格分隔——分别表示石子堆的数量和颜色种类数。
第二行包含 n 个正整数 a1, a2, ..., an(1 ≤ ai ≤ 100),表示每堆石子的数量。
输出格式
If there is no way to paint the pebbles satisfying the given condition, output "NO" (without quotes) .
Otherwise in the first line output "YES" (without quotes). Then n lines should follow, the i-th of them should contain a__i space-separated integers. j-th (1 ≤ j ≤ a__i) of these integers should be equal to the color of the j-th pebble in the i-th pile. If there are several possible answers, you may output any of them.
如果不存在满足给定条件的涂色方案,则输出 “NO”(不带引号)。
否则,第一行输出 “YES”(不带引号)。随后输出 n 行,其中第 i 行应包含 a__i 个以空格分隔的整数;这些整数中第 j 个(1 ≤ j ≤ a__i)应等于第 i 堆中第 j 颗鹅卵石的颜色。若存在多种可行解,输出任意一种即可。
输入输出样例
输入#1
4 4 1 2 3 4
输出#1
YES 1 1 4 1 2 4 1 2 3 4
输入#2
5 2 3 2 4 1 3
输出#2
NO
输入#3
5 4 3 2 4 3 5
输出#3
YES 1 2 3 1 3 1 2 3 4 1 3 4 1 1 2 3 4
输入解题思路,AI测评打分。不知道怎么写?