B. Painting Pebbles
1 second
256 megabytes
standard input
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.
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.
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.
4 4
1 2 3 4
YES
1
1 4
1 2 4
1 2 3 4
5 2
3 2 4 1 3
NO
5 4
3 2 4 3 5
YES
1 2 3
1 3
1 2 3 4
1 3 4
1 1 2 3 4
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <cctype>
#include <cassert>
#include <typeinfo>
#include <utility> //std::move()
using namespace std;
const int INF = 0x7fffffff;
const double EXP = 1e-;
const int MS = ;
typedef long long LL; int a[MS];
int main()
{
int n, k, i, j;
cin >> n >> k;
int mini = INF, maxi = -INF;
for (int i = ; i < n; i++)
{
cin >> a[i];
if (mini>a[i])
mini = a[i];
if (maxi < a[i])
maxi= a[i];
}
if ((maxi / k - )*k+ maxi%k > mini)
{
cout << "NO" << endl;
}
else
{
cout << "YES" << endl;
for (i = ; i < n; i++)
{
for (j = ; j < a[i]; j++)
{
if (j)
cout << " ";
cout << j%k + ;
}
cout << endl;
}
}
return ;
}
B. Painting Pebbles的更多相关文章
- cf509B Painting Pebbles
B. Painting Pebbles time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces 509 B题 Painting Pebbles
转载地址:http://blog.csdn.net/nike0good/article/details/43449739 B. Painting Pebbles time limit per test ...
- codeforces 507B. Painting Pebbles 解题报告
题目链接:http://codeforces.com/problemset/problem/509/B 题目意思:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色 ...
- 贪心 Codeforces Round #289 (Div. 2, ACM ICPC Rules) B. Painting Pebbles
题目传送门 /* 题意:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色去填充所有存在的pebbles, 使得任意两个piles,用颜色c填充的pebbles数量 ...
- 【codeforces 509B】Painting Pebbles
[题目链接]:http://codeforces.com/contest/509/problem/B [题意] 给n鹅卵石染色; 有k种颜色可供选择; 问你有没有染色方案; 使得各个堆的鹅卵石里面,第 ...
- codeforces509B
Painting Pebbles CodeForces - 509B There are n piles of pebbles on the table, the i-th pile contains ...
- 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]即 ...
- CF448C Painting Fence (分治递归)
Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per tes ...
- [译]使用Continuous painting mode来分析页面的绘制状态
Chrome Canary(Chrome “金丝雀版本”)目前已经支持Continuous painting mode,用于分析页面性能.这篇文章将会介绍怎么才能页面在绘制过程中找到问题和怎么利用这个 ...
随机推荐
- reverse the string word by word
题目:Given an input string, reverse the string word by word. For example,Given s = "the sky is bl ...
- apache环境下配置服务器支持https
SSL加密的意义在于保护服务器到客户端的信息或者是客户端到服务器的信息不被监听和篡改. 现在一些主流的网站都已经是通过 https访问了,搜索引擎对此类网站的收录也不存在问题了. 具体的配置流程大概是 ...
- [Hive - LanguageManual] Alter Table/Partition/Column
Alter Table/Partition/Column Alter Table Rename Table Alter Table Properties Alter Table Comment Add ...
- Classes and Objects :类和对象(1)
类的定义:修饰符,class,类名,extends,逗号分隔的implements,类体{}规范的类名:首字母要大写,以后每个单词首字母都大写字段的定义:修饰符,类型,字段名按照封装的思想,字段通常定 ...
- Things App Engine Doesn't Do...Yet
当人们第一次使用App Engine的时候,他们会问一些App Engine不会做的事情.其中的一些事情Google在不久的将来会实现的,还有一些违背了App Engine设计的本质,将不可能增加(到 ...
- 5个让人激动的Java项目
每个Java/JVM领域的技术专家都应从那些项目中获益,他们中有2011在SanJose举办的Jax 会议中提名为最好的技术产品奖的.我之所以选择它们,是因为它们可以广泛用于一系列的项目中,解决真实问 ...
- 第三百零一天 how can i 坚持
其实真搞不大懂自己.不喜欢巴结人,也不喜欢阿谀奉承,但老是感觉自己却又在那么做,是对自己要求太高了,想太多?? 郭娜好像把我拉黑了,拉黑就拉黑吧.或许真不合适. 睡觉.
- Apache Spark BlinkDB
BlinkDB是一个用于在海量数据上进行交互式SQL的近似查询引擎. 它允许用户通过在查询准确性和查询响应时间之间做出权衡,完成近似查询. 其数据的精度被控制在允许的误差范围内. 为了达到这个目标,B ...
- Winter is coming Just have a little faith. JSF框架简介与实例
JSF 体系结构: JSF 的主要优势之一就是它既是Java Web应用程序的用户界面标准又是严格遵循模型-视图-控制器 (MVC) 设计模式的框架.用户界面代码(视图)与应用程序数据和逻辑(模型)的 ...
- [iOS基础控件 - 6.12.1] QQ菜单管理 UITabBarController 控制器管理
A.需求 1.类似QQ.微信顶部或者底部的窗口转换导航条 2.给每个页面添加相应内容 B.UITabBarController 1.基本概念: (1)内容高度 iOS7之前内容高度为:屏幕高度 - ...