B. Painting Pebbles
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output

There are n piles of pebbles on the table, the i-th pile contains ai 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 bi, 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 |bi, c - bj, c| ≤ 1. It isn't necessary to use all k colors: if color c hasn't been used in pile i, then bi, c is considered to be zero.

Input

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 a1, a2, ..., an (1 ≤ ai ≤ 100) denoting number of pebbles in each of the piles.

Output

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 ai space-separated integers. j-th (1 ≤ j ≤ ai) 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.

Sample test(s)
input
4 4
1 2 3 4
output
YES
1
1 4
1 2 4
1 2 3 4
input
5 2
3 2 4 1 3
output
NO
input
5 4
3 2 4 3 5
output
YES
1 2 3
1 3
1 2 3 4
1 3 4
1 1 2 3 4 题意是给出一种染色方案,使得第i行有a[i]个元素,任意两行中任意两种颜色的元素个数相差不超过1
如果max-min>k,直接输出NO
否则直接每行模拟就好了
就是第i+tk的全染第i种颜色(t>=0)
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
inline void write(LL a)
{
if (a<0){printf("-");a=-a;}
if (a>=10)write(a/10);
putchar(a%10+'0');
}
inline void writeln(LL a){write(a);printf("\n");}
int a[110];
int s[110];
int n,m,mx,mn=inf;
int main()
{
n=read();m=read();
for (int i=1;i<=n;i++)
{
a[i]=read();
mx=max(mx,a[i]);
mn=min(mn,a[i]);
}
if (mx-mn>m)
{
printf("NO\n");
return 0;
}
printf("YES\n");
for (int i=1;i<=n;i++)
{
memset(s,0,sizeof(s));
int now=1;
for (int j=1;j<=a[i];j++)
{
s[now++]++;
if (now>m)now=1;
}
for (int j=1;j<=m;j++)
for (int k=1;k<=s[j];k++)
printf("%d ",j);
printf("\n");
} }

cf509B Painting Pebbles的更多相关文章

  1. B. Painting Pebbles

    B. Painting Pebbles time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. codeforces 509 B题 Painting Pebbles

    转载地址:http://blog.csdn.net/nike0good/article/details/43449739 B. Painting Pebbles time limit per test ...

  3. codeforces 507B. Painting Pebbles 解题报告

    题目链接:http://codeforces.com/problemset/problem/509/B 题目意思:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色 ...

  4. 贪心 Codeforces Round #289 (Div. 2, ACM ICPC Rules) B. Painting Pebbles

    题目传送门 /* 题意:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色去填充所有存在的pebbles, 使得任意两个piles,用颜色c填充的pebbles数量 ...

  5. 【codeforces 509B】Painting Pebbles

    [题目链接]:http://codeforces.com/contest/509/problem/B [题意] 给n鹅卵石染色; 有k种颜色可供选择; 问你有没有染色方案; 使得各个堆的鹅卵石里面,第 ...

  6. codeforces509B

    Painting Pebbles CodeForces - 509B There are n piles of pebbles on the table, the i-th pile contains ...

  7. Codeforces Round #289 Div 2

    A. Maximum in Table 题意:给定一个表格,它的第一行全为1,第一列全为1,另外的数满足a[i][j]=a[i-1][j]+a[i][j-1],求这个表格中的最大的数 a[n][n]即 ...

  8. CF448C Painting Fence (分治递归)

    Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per tes ...

  9. [译]使用Continuous painting mode来分析页面的绘制状态

    Chrome Canary(Chrome “金丝雀版本”)目前已经支持Continuous painting mode,用于分析页面性能.这篇文章将会介绍怎么才能页面在绘制过程中找到问题和怎么利用这个 ...

随机推荐

  1. Java基础知识强化70:正则表达式之引入案例(QQ号码校验)

    1. 校验QQ号码的案例,如下: package cn.itcast_01; import java.util.Scanner; /* * 校验qq号码. * 1:要求必须是5-15位数字 * 2:0 ...

  2. js函数中变量的作用域

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  3. c#委托中另外一种用法

    在c#委托中,经常可能遇到函数重载的情况,可是又需要在一个函数中调用这些函数,一般我都是根据多个函数重载个数,也写上这么多个函数重载.比如 public double T1(int r) { retu ...

  4. codevs 1028 花店橱窗布置 (KM)

    /*裸地KM*/ #include<iostream> #include<cstdio> #include<cstring> #define maxn 110 #d ...

  5. ASP.NET-FineUI开发实践-10

    嵌套Grid,光棍月大放送,不藏着掖着.实在写的不好,没脸藏啊~只考虑显示排序修改什么的都不管! 话说三石官网加实例了,http://fineui.com/demo/#/demo/grid/grid_ ...

  6. requirejs和r.js的心得

    requirejs的GitHub:requirejs r.js的GitHub:r.js grunt-contrib-requirejs的GitHub:grunt-contrib-requirejs r ...

  7. Android开发中在一个Activity中关闭另一个Activity

    比如有ActivityA, ActivityB,在ActivityB中关闭ActivityA 解决方案: 1. 在 ActivityA 里面设置一个静态的变量instance,初始化为this在 Ac ...

  8. HTML5 学习

    1.<header> 标签定义文档的页眉(介绍信息) 标签是 HTML 5 中的新标签 <header> <h1>Welcome to my homepage< ...

  9. PHP 错误处理

    PHP 错误处理 在 PHP 中,默认的错误处理很简单.一条错误消息会被发送到浏览器,这条消息带有文件名.行号以及描述错误的消息. PHP 错误处理 在创建脚本和 Web 应用程序时,错误处理是一个重 ...

  10. 如何退出Activity?如何安全退出已调用多个Activity的Application?

    如何退出Activity?如何安全退出已调用多个Activity的Application? 退出Activity直接调用finish()方法  //用户点击back键就是退出一个Activity 退出 ...