#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int NN = 22;
int n, p;
struct trip {
  int s, e, t, id;
  void input(int _id) {
    scanf("%d %d %d", &s, &e, &t);
    e += s;
    id = _id;
  }
  bool operator<(const trip tmp) const { return s < tmp.s; }
} t[NN];
long long dp[1 << NN];
int pre[1 << NN];
int st[1 << NN];
int pass[NN], day[NN];
int flag[NN];
inline bool smin(long long &u, long long v) { return u > v ? u = v, 1 : 0; }
int ni, i, j;
inline bool update(int d) {
  for (int k = 0; k < n; k++) {
    if ((ni >> k) & 1) {
      if (t[k].s < d) {
        if (t[k].e > d) return 0;
      } else {
        if (t[k].s <= d + t[j].t) return 0;
        break;
      }
    } else {
      if (t[k].s <= d and t[k].e > d) return 0;
    }
  }
  dp[ni] = d + t[j].t;
  pre[ni] = j;
  st[ni] = d;
  return 1;
}
void up(int u, int p) {
  while (u) {
    int v = pre[u];
    pass[t[v].id] = p;
    day[t[v].id] = st[u];
    u ^= 1 << v;
  }
}
int solve() {
  cin >> n >> p;
  for (i = 0; i < n; i++) t[i].input(i);
  sort(t, t + n);
  for (int i = 0; i < n - 1; i++)
    if (t[i].e != t[i + 1].s) flag[i] = 1;
  flag[n - 1] = 1;
  for (i = 0; i < 1 << n; i++) dp[i] = INF;
  dp[0] = 1;
  int ed = 1 << n;
  for (i = 0; i < ed - 1; i++)
    if (dp[i] < INF) {
      for (j = 0; j < n; j++)
        if (!((i >> j) & 1)) {
          ni = i ^ (1 << j);
          if (dp[i] + t[j].t >= t[j].s or dp[i] + t[j].t >= dp[ni]) continue;
          if (update(dp[i])) continue;
          int k = 0, u = ni;
          int mn = t[__builtin_ctz(u)].s;
          while (k < j and t[k].e <= dp[i]) {
            if ((u >> k) & 1) u ^= 1 << k, mn = t[__builtin_ctz(u)].s;
            k++;
          }
          while (k < j) {
            if ((u >> k) & 1) u ^= 1 << k, mn = t[__builtin_ctz(u)].s;
            if (flag[k] and t[k].e + t[j].t < mn) {
              if (smin(dp[ni], t[k].e + t[j].t)) {
                pre[ni] = j;
                st[ni] = t[k].e;
              }
            }
            k++;
          }
        }
    }
  if (p == 1) {
    if (dp[ed - 1] == INF) return puts("NO");
    puts("YES");
    int u = ed - 1;
    up(u, 1);
    for (int i = 0; i < n; i++) printf("%d %d\n", pass[i], day[i]);
    return 0;
  }
  for (int i = 0; i < 1 << n; i++)
    if (dp[i] < INF and dp[ed - i - 1] < INF) {
      puts("YES");
      up(i, 1);
      up(ed - i - 1, 2);
      for (int i = 0; i < n; i++) printf("%d %d\n", pass[i], day[i]);
      return 0;
    }
  puts("NO");
}
int main() {
  solve();
  return 0;
}
