A9867. Painting Pebbles
编程题
普及/提高-
知识点
题目描述
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.
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.
输入格式
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.
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.
输出格式
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.
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.
输入输出样例
输入 #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