#include <bits/stdc++.h>
template <typename Y>
inline bool updmin(Y &a, Y b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename Y>
inline bool updmax(Y &a, Y b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename Y>
inline Y abs(Y a) {
  if (a < 0) a = -a;
  return a;
}
template <typename Y>
inline Y sqr(Y a) {
  return a * a;
}
int read() {
  int w = 1, q = 0, ch = ' ';
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') w = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) q = q * 10 + ch - 48;
  return q * w;
}
inline void FileIO() {
  freopen(
      ""
      ".in",
      "r", stdin);
  freopen(
      ""
      ".out",
      "w", stdout);
}
const int N = 22;
int n, p, s[N], len[N], t[N];
int f[1 << N], pre[1 << N];
int perm[N], perm2[N];
int tim[N], id[N];
int tmpf[N];
inline int Find(int S, int last, int x) {
  for (int _ = 0; _ < n; _++) {
    if (last + t[x] >= s[x]) return -1;
    int p = perm[_];
    if (s[p] <= last && s[p] + len[p] - 1 >= last) {
      last = s[p] + len[p];
      continue;
    }
    if (!((S >> p) & 1) || s[p] <= last) continue;
    if (last + t[x] < s[p]) return last;
    last = s[p] + len[p];
  }
  return -1;
}
inline void Solve(int S, int last) {
  int pt = 0;
  for (int _ = 0; _ < n; _++) {
    int p = perm[_];
    if (s[p] <= last && s[p] + len[p] - 1 >= last) {
      last = s[p] + len[p];
      continue;
    }
    if (!((S >> p) & 1) || s[p] <= last) continue;
    while (pt < n && last + t[perm2[pt]] < s[p]) {
      tmpf[perm2[pt++]] = last;
    }
    last = s[p] + len[p];
  }
  while (pt < n) {
    tmpf[perm2[pt++]] = last;
  }
}
void Out(int idx, int S) {
  if (!S) return;
  int T = pre[S];
  int x = 31 - __builtin_clz(S - T);
  id[x] = idx;
  tim[x] = Find(S, f[T], x);
  Out(idx, T);
}
int main() {
  n = read();
  p = read();
  for (int i = 0; i < n; i++) {
    s[i] = read();
    len[i] = read();
    t[i] = read();
    perm[i] = i;
    perm2[i] = i;
  }
  std::sort(perm, perm + n, [&](int a, int b) { return s[a] < s[b]; });
  std::sort(perm2, perm2 + n, [&](int a, int b) { return t[a] < t[b]; });
  memset(f, 0x3f, sizeof f);
  f[0] = 1;
  for (int S = 0; S < 1 << n; S++) {
    if (f[S] == 0x3f3f3f3f) continue;
    Solve(S, f[S]);
    for (int x = 0; x < n; x++) {
      if ((S >> x) & 1) continue;
      if (s[x] <= f[S]) continue;
      int u = tmpf[x];
      if (u + t[x] >= s[x]) continue;
      if (updmin(f[S | 1 << x], u + t[x])) {
        pre[S | 1 << x] = S;
      }
    }
  }
  int U = (1 << n) - 1;
  if (p == 1) {
    if (f[U] == 0x3f3f3f3f) {
      puts("NO");
    } else {
      puts("YES");
      Out(1, U);
      for (int i = 0; i < n; i++) {
        printf("%d %d\n", id[i], tim[i]);
      }
    }
  } else {
    int ok = 0;
    for (int S = 0; S < 1 << n; S++) {
      if (f[S] != 0x3f3f3f3f && f[U ^ S] != 0x3f3f3f3f) {
        ok = 1;
        Out(1, S);
        Out(2, U ^ S);
        break;
      }
    }
    if (!ok) {
      puts("NO");
    } else {
      puts("YES");
      for (int i = 0; i < n; i++) {
        printf("%d %d\n", id[i], tim[i]);
      }
    }
  }
  return 0;
}
