#include <bits/stdc++.h>
template <typename T>
inline void read(T& x) {
  x = 0;
  T w = 1, ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') w = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);
  x = x * w;
}
template <typename T, typename... Args>
inline void read(T& t, Args&... args) {
  read(t);
  read(args...);
}
const int N = 305;
const long long inf = 1e9 + 7;
long long n, t, K;
long long a[N], b[N], c[N], A[N], B[N], f[N][N][2], g[N][N][2];
int main() {
  read(n, t, K);
  for (register int i = 1; i <= n; ++i) read(a[i], b[i], c[i]);
  ++n;
  a[n] = c[n] = inf;
  b[n] = 0;
  for (register int i = 1; i <= n; ++i)
    A[i] = A[i - 1] + a[i], B[i] = B[i - 1] + b[i];
  for (register int i = 1; i <= n; ++i)
    for (register int j = 0; j <= t; ++j)
      for (register int k = 0; k <= 1; ++k) f[i][j][k] = g[i][j][k] = inf;
  for (register int i = 1; i <= n; ++i)
    for (register int j = 0; j <= t; ++j)
      for (register int k = 0; k <= 1; ++k) {
        if (f[i - 1][j][k] != inf && a[i] * k + b[i] * j <= c[i]) {
          long long val = (k * A[i - 1] + j * B[i - 1] + K - 1) / K;
          f[i][j][k] = std::min(f[i][j][k], f[i - 1][j][k]);
          if (val * K <= k * A[i] + j * B[i])
            g[i][j][k] = std::min(g[i][j][k], val);
        }
        for (register int l = 0; l <= j; ++l) {
          long long m = k * A[i] + l * B[i] - K * g[i][l][k];
          long long x = (std::max(m + (j - l) * b[i] - c[i], 0ll) + K - 1) / K;
          if (m < x * K) continue;
          if (g[i][l][k] == inf) continue;
          if (f[i - 1][j - l][0] == inf) continue;
          long long val = ((j - l) * B[i - 1] + K - 1) / K;
          f[i][j][k] =
              std::min(f[i][j][k], g[i][l][k] + f[i - 1][j - l][0] + x);
          if (val * K <= (j - l) * B[i] + (m - x * K))
            g[i][j][k] = std::min(g[i][j][k], g[i][l][k] + val + x);
        }
      }
  printf("%lld\n", f[n][t][1]);
  return 0;
}
