#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
using namespace std;
const long long N = 3e2 + 10, OO = 1e18 + 7, T = 1e6 + 10, mod = 1e9 + 7,
                M = 1e9 + 7, P = 6151, SQ = 280, lg = 70;
long long n, t, k;
long long sa[N], sb[N];
long long a[N], b[N], c[N];
long long d[N][N][2], g[N][N][2];
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> t >> k;
  for (long long i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i];
  a[++n] = OO, b[n] = 0, c[n] = OO;
  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 p = 1; p <= n; p++) {
    for (long long s = 0; s <= t; s++) {
      for (long long z = 0; z < 2; z++) {
        d[p][s][z] = g[p][s][z] = OO;
        if (d[p - 1][s][z] < OO && a[p] * z + b[p] * s <= c[p]) {
          d[p][s][z] = d[p - 1][s][z];
          long long dt = (sa[p - 1] * z + sb[p - 1] * s + k - 1) / k;
          if (dt * k <= sa[p] * z + sb[p] * s) g[p][s][z] = dt;
        }
        for (long long r = 0; r < s; r++) {
          if (g[p][r][z] < OO) {
            long long m = sa[p] * z + sb[p] * r - g[p][r][z] * k;
            long long x = (max(m + (s - r) * b[p] - c[p], 0ll) + k - 1) / k;
            m -= x * k;
            if (d[p - 1][s - r][0] < OO && m >= 0) {
              d[p][s][z] = min(d[p][s][z], g[p][r][z] + x + d[p - 1][s - r][0]);
              long long dt = (sb[p - 1] * (s - r) + k - 1) / k;
              if (dt * k <= m + (s - r) * sb[p])
                g[p][s][z] = min(g[p][s][z], g[p][r][z] + x + dt);
            }
          }
        }
      }
    }
  }
  cout << d[n][t][1] << endl;
  return 0;
}
