#include <bits/stdc++.h>
long long f[201][201];
long long n, t, k, a[201], b[201], c[201];
long long h[201], g[201][201], d[201];
void brute() {
  for (long long j = 1; j <= n; j++) g[0][j] = g[0][j - 1] + d[j];
  for (long long i = 1; i <= t; i++) {
    long long mx = 0;
    for (long long j = 1; j <= n; j++)
      if (d[j] + b[j] > c[j]) mx = j;
    h[i] = h[i - 1];
    if (mx) {
      long long tot = d[mx] + b[mx] - c[mx];
      d[mx] -= tot;
      for (long long j = 1; j < mx; j++) tot += d[j], d[j] = 0;
      h[i] += ((tot + k - 1) / k);
      tot = (((tot + k - 1) / k) * k) - tot;
      while (mx <= n && tot) {
        long long v = std::min(d[mx], tot);
        d[mx] -= v;
        tot -= v;
        ++mx;
      }
    }
    for (long long j = 1; j <= n; j++) {
      d[j] += b[j];
      g[i][j] = g[i][j - 1] + d[j];
    }
  }
}
signed main() {
  scanf("%lld%lld%lld", &n, &t, &k);
  for (long long i = 1; i <= n; i++) scanf("%lld%lld%lld", a + i, b + i, c + i);
  while (n && a[n] + 1ll * t * b[n] <= c[n]) --n;
  if (!n) {
    puts("0");
    return 0;
  }
  for (long long i = 1; i < n; i++) {
    for (long long j = 1; j <= n; j++) d[j] = (j <= i) ? 0 : (-1e14);
    brute();
    for (long long j = 1; j <= t; j++) {
      f[i][j] = 1e14;
      for (long long k = 0; k <= j; k++) {
        if (1ll * b[i] * (j - k) > c[i]) continue;
        long long v =
            g[k][i - 1] +
            std::max(g[k][i] - g[k][i - 1] + 1ll * b[i] * (j - k) - c[i], 0ll);
        f[i][j] =
            std::min(f[i][j], f[i - 1][j - k] + h[k] + ((v + ::k - 1) / ::k));
      }
    }
  }
  for (long long j = 1; j <= n; j++) d[j] = a[j];
  brute();
  long long ans = 1e14;
  for (long long i = 0; i <= t; i++) {
    if (1ll * b[n] * (t - i) > c[n]) continue;
    long long v =
        g[i][n - 1] +
        std::max(g[i][n] - g[i][n - 1] + 1ll * b[n] * (t - i) - c[n], 0ll);
    ans = std::min(ans, f[n - 1][t - i] + h[i] + ((v + k - 1) / k));
  }
  printf("%lld\n", ans);
}
