#include <bits/stdc++.h>
using namespace std;
int n, t, k;
long long a[666666], b[666666], c[666666], sa[666666], sb[666666], sc[666666];
long long d[235][235][235], g[235][235][235];
inline void cmin(long long& a, long long b) {
  if (a > b) a = b;
}
int main() {
  cin >> n >> t >> k;
  ++n;
  const long long inf = 1e18;
  for (int i = 1; i <= n; ++i) {
    if (i == n)
      a[i] = c[i] = inf;
    else
      cin >> a[i] >> b[i] >> c[i];
    sa[i] = sa[i - 1] + a[i];
    sb[i] = sb[i - 1] + b[i];
    sc[i] = sc[i - 1] + c[i];
  }
  for (int p = 1; p <= n; ++p)
    for (int s = 0; s <= t; ++s)
      for (int z = 0; z < 2; ++z) {
        d[p][s][z] = g[p][s][z] = inf;
        if (s * b[p] + z * a[p] <= c[p] && d[p - 1][s][z] < inf) {
          d[p][s][z] = d[p - 1][s][z];
          long long v = (z * sa[p - 1] + s * sb[p - 1] + k - 1) / k;
          if (v * k <= z * sa[p] + s * sb[p]) g[p][s][z] = v;
        }
        for (int r = 0; r < s; ++r)
          if (g[p][r][z] < inf) {
            long long m = z * sa[p] + r * sb[p] - k * g[p][r][z];
            long long x = (max(m + (s - r) * b[p] - c[p], 0LL) + k - 1) / k;
            if (x * k <= m && d[p - 1][s - r][0] < inf) {
              cmin(d[p][s][z], g[p][r][z] + x + d[p - 1][s - r][0]);
              long long v = ((s - r) * sb[p - 1] + k - 1) / k;
              if (v * k <= (s - r) * sb[p] + m - x * k)
                cmin(g[p][s][z], g[p][r][z] + x + v);
            }
          }
      }
  cout << d[n][t][1] << "\n";
}
