A9867 | Painting Pebbles
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted