fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define FOR(i, a, b) for(int i=a;i<=b;i++)
  4. int a[102], c1[102], c2[102];
  5. int main() {
  6. int n, k;
  7. scanf("%d %d",&n, &k);
  8. FOR(i, 0, n-1) scanf("%d",&a[i]);
  9. vector < vector < int > > v(n);
  10. FOR(i, 0, n-1) v[i].resize(a[i]);
  11. FOR(i, 0, n-1) {
  12. FOR(j, 0, a[i]-1) {
  13. v[i][j] = j%k;
  14. v[i][j]++;
  15. }
  16. }
  17. bool f = true;
  18. FOR(i, 0, n-1) {
  19. FOR(j, i+1, n-1) {
  20. FOR(K, 0, 102) {
  21. c1[K] = 0;
  22. c2[K] = 0;
  23. }
  24. FOR(K, 0, a[i]-1) c1[v[i][K]]++;
  25. FOR(K, 0, a[j]-1) c2[v[j][K]]++;
  26. FOR(K, 0, 102) {
  27. if(abs(c1[K]- c2[K]) > 1) {
  28. f = false;
  29. break;
  30. }
  31. }
  32. if(!f) break;
  33. }
  34. if(!f) break;
  35. }
  36. if(f) {
  37. puts("YES");
  38. FOR(i, 0, v.size()-1) {
  39. FOR(j, 0, v[i].size()-1) printf("%d ",v[i][j]);
  40. puts("");
  41. }
  42. }
  43. else puts("NO");
  44. return 0;
  45. }
Success #stdin #stdout 0s 3276KB
stdin
4 4
1 2 3 4
stdout
NO