B. Painting Pebbles

52 篇文章 1 订阅

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.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 a 1, a 2, …, a n (1 ≤ a i ≤ 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 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.ExamplesinputCopy

4 4
1 2 3 4

outputCopy

YES
1
1 4
1 2 4
1 2 3 4

inputCopy

5 2
3 2 4 1 3

outputCopy

NO

inputCopy

5 4
3 2 4 3 5

outputCopy

YES
1 2 3
1 3
1 2 3 4
1 3 4
1 1 2 3 4

思路:一个个轮换着用就行了。这样是最节省的,如果这样还不满足就是NO,不然就这么模拟。

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=400;
typedef long long LL;
LL a[maxn]; 
LL b[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n,k;cin>>n>>k;
  for(LL i=1;i<=n;i++) cin>>a[i],b[i]=a[i];
  sort(b+1,b+1+n);
  if((b[n]-b[1])>k) cout<<"NO"<<endl;
  else
  {
  	cout<<"YES"<<endl;
  	for(LL i=1;i<=n;i++)
  	{
  		LL ans=1;
  		for(LL j=1;j<=a[i];j++)
		  {
		  	  cout<<ans<<" ";ans++;
		  	  if(ans>k) ans-=k;
		  }	
		 cout<<endl; 
	} 
  }
return 0;
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值