#include <bits/stdc++.h>
using namespace std;
int n, t, K;
long long a[200 + 5], b[200 + 5], c[200 + 5];
long long suma[200 + 5], sumb[200 + 5];
long long f[200 + 5][200 + 5][2], g[200 + 5][200 + 5][2];
int main() {
  scanf("%d %d %d", &n, &t, &K);
  for (int i = 1; i <= n; i++) scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);
  n++;
  a[n] = b[n] = (1ll << 31);
  c[n] = 0x3f3f3f3f3f3f3f3f;
  for (int i = 1; i <= n; i++) {
    suma[i] = suma[i - 1] + a[i];
    sumb[i] = sumb[i - 1] + b[i];
  }
  memset(f, 0x3f, sizeof(f));
  memset(g, 0x3f, sizeof(g));
  for (int j = 0; j <= t; j++)
    f[0][j][0] = f[0][j][1] = g[0][j][0] = g[0][j][1] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= t; j++) {
      for (int u = 0; u <= 1; u++) {
        if (u * a[i] + j * b[i] <= c[i] &&
            f[i - 1][j][u] != 0x3f3f3f3f3f3f3f3f) {
          f[i][j][u] = min(f[i][j][u], f[i - 1][j][u]);
          long long num = (u * suma[i - 1] + j * sumb[i - 1] + K - 1) / K;
          if (K * num <= u * suma[i] + j * sumb[i])
            g[i][j][u] = min(g[i][j][u], num);
        }
        for (int r = 0; r < j; r++) {
          if (g[i][r][u] != 0x3f3f3f3f3f3f3f3f) {
            long long rem = u * suma[i] + r * sumb[i] - K * g[i][r][u];
            long long need =
                (max(rem + (j - r) * b[i] - c[i], 0ll) + K - 1) / K;
            if (need * K <= rem && f[i - 1][j - r][0] != 0x3f3f3f3f3f3f3f3f) {
              f[i][j][u] =
                  min(f[i][j][u], g[i][r][u] + need + f[i - 1][j - r][0]);
              long long num = ((j - r) * sumb[i - 1] + K - 1) / K;
              if (num * K <= (j - r) * sumb[i] + (rem - need * K))
                g[i][j][u] = min(g[i][j][u], g[i][r][u] + need + num);
            }
          }
        }
      }
    }
  }
  printf("%lld\n", f[n][t][1]);
}
