#include <bits/stdc++.h>
long long f[2][210][210], g[2][210][210], a[210], b[210], c[210], n, Sa[210],
    Sb[210], t, K;
signed main() {
  scanf("%d%d%d", &n, &t, &K);
  for (long long i = 1; i <= n; i++) scanf("%d%d%d", a + i, b + i, c + i);
  ++n;
  a[n] = 1e18, b[n] = 0, c[n] = 1e18;
  for (long long i = 1; i <= n; i++)
    Sa[i] = Sa[i - 1] + a[i], Sb[i] = Sb[i - 1] + b[i];
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= t; j++) {
      g[0][i][j] = g[1][i][j] = 1e18;
      for (long long k = 0; k < j; k++) {
        if (g[1][i][k] == 1e18 || g[0][i - 1][j - k] == 1e18) continue;
        long long left = Sb[i] * k - g[1][i][k] * K;
        if (left % K + b[i] * (j - k) <= c[i]) {
          long long x = Sb[i - 1] * (j - k) - g[0][i - 1][j - k] * K,
                    y = left + b[i] * (j - k),
                    z = std::max((y - c[i] + K - 1) / K, 0ll);
          if (z || y <= c[i])
            g[0][i][j] =
                std::min(g[0][i][j], g[1][i][k] + g[0][i - 1][j - k] + z);
          if (((x + K - 1) / K) * K <= x + y - z * K)
            g[1][i][j] = std::min(g[1][i][j], g[1][i][k] + g[0][i - 1][j - k] +
                                                  z + (x + K - 1) / K);
        }
      }
      if (g[0][i - 1][j] != 1e18) {
        long long left = b[i] * j;
        if (left <= c[i]) {
          long long x = Sb[i - 1] * j - g[0][i - 1][j] * K, y = left,
                    z = std::max((y - c[i] + K - 1) / K, 0ll);
          g[0][i][j] = std::min(g[0][i][j], g[0][i - 1][j]);
          if (((x + K - 1) / K) * K <= x + y)
            g[1][i][j] = std::min(g[1][i][j], g[0][i - 1][j] + (x + K - 1) / K);
        }
      }
    }
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= t; j++) {
      f[0][i][j] = f[1][i][j] = 1e18;
      for (long long k = 0; k < j; k++) {
        if (f[1][i][k] == 1e18 || g[0][i - 1][j - k] == 1e18) continue;
        long long left = Sa[i] + Sb[i] * k - f[1][i][k] * K;
        if (left % K + b[i] * (j - k) <= c[i]) {
          long long x = Sb[i - 1] * (j - k) - g[0][i - 1][j - k] * K,
                    y = left + b[i] * (j - k),
                    z = std::max((y - c[i] + K - 1) / K, 0ll);
          if (z || y <= c[i])
            f[0][i][j] =
                std::min(f[0][i][j], f[1][i][k] + g[0][i - 1][j - k] + z);
          if (((x + K - 1) / K) * K <= x + y - z * K)
            f[1][i][j] = std::min(f[1][i][j], f[1][i][k] + g[0][i - 1][j - k] +
                                                  z + (x + K - 1) / K);
        }
      }
      if (f[0][i - 1][j] != 1e18) {
        long long left = a[i] + b[i] * j;
        if (left <= c[i]) {
          long long x = Sa[i - 1] + Sb[i - 1] * j - f[0][i - 1][j] * K,
                    y = left, z = std::max((y - c[i] + K - 1) / K, 0ll);
          f[0][i][j] = std::min(f[0][i][j], f[0][i - 1][j]);
          if (((x + K - 1) / K) * K <= x + y)
            f[1][i][j] = std::min(f[1][i][j], f[0][i - 1][j] + (x + K - 1) / K);
        }
      }
    }
  printf("%lld\n", f[0][n][t]);
}
