There is n piles of pebbles on the table, the i-th pile contains ai p Ebbles. Your task is-to-paint each pebble using one of the K given colors so, for each color c an D any II piles i and J The difference between the number of pebbles of color c< /c17> in pile I and number of pebbles of the color c in pile J are at the most one.
In and 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 < Span class= "Tex-span" > b i , C is considered to be zero.
Input
The first line of the input contains positive integers n and k (1≤ n, k ≤ Separated by a space-the number of piles and the number of colors respectively.
The second line contains n positive integers a1, a2, ..., a c15>n (1≤ ai ≤100) denoting number of pebbles in each of the piles.
Output
If there is no-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-s eparated 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 is several possible answers, you could output any of the them.
Sample Input
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
/* The number from less to more order, to determine whether it is possible, as long as the number of cycles and where the cycle can be easily judged, if the number of cycles of the difference is greater than 1 and the number of bad digits is greater than 1 then certainly not, for example:m = 2 a[1] = 2, a[2] = 5 1 2 b[1] = 1 C[1] = 0; 1 2 1 2 1 b[1] = 2 c[2] = 1 If the number of cycles is worse than 2, it's definitely not possible. If you can output the current value directly based on the loop and bit/#include <cstdio> #include <cstring > #include <algorithm>using namespace std;struct edge{int A, b, C;} G[110];bool CMP (Edge I, Edge j) {return I.A < j.a;} int main () {int n, m; int a[110]; int b[110]; int c[110]; while (~SCANF ("%d%d", &n, &m)) {for (int i = 1; I <= n; i++) scanf ("%d", &a[i]); for (int i = 1; I <= n; i++) {int k = a[i]/m; int t = a[i]% m; B[i] = k; C[i] = t; } for (int i = 1; I <= n; i++) {g[i].a = A[i]; g[i].b = B[i]; G[I].C = C[i]; } sort (g + 1, G + N + 1, CMP); /* for (int i = 1; I <= n; i++) {printf ("%d%d%d", g[i].a, g[i].b, g[i].c); Puts (""); } */INT flag = 0; for (int i = 1, i <= N; i++) {for (int j = i + 1; j <= N; j + +) {if (g[j].b > G[i].b & ;& g[j].c > G[i].c | | G[J].B-G[I].B >= 2) {flag = 1; Break }} if (flag = = 1) break; } if (flag = = 1) {printf ("no\n");} else {printf ("yes\n"); for (int i = 1, i <= N; i++) {for (int j = 1; J <= B[i]; j + +) {for (int k = 1; k < ; = m; k++) printf ("%d", k); } for (int j = 1; J <= C[i]; j + +) printf ("%d", j); Puts (""); }}} return 0;}
Codeforces Round #289 (Div. 2, ACM ICPC Rules)--b greedy--painting Pebbles