#include <bits/stdc++.h>
constexpr int N(205);
constexpr long long inf(0x3f3f3f3f3f3f3f3f);
void Min(long long &x, long long y) { x > y && (x = y); }
int main(void) {
  int n, t;
  long long k;
  scanf("%d%d%lld", &n, &t, &k);
  static long long a[N], b[N], c[N], sa[N], sb[N], sc[N];
  for (int i(1); i <= n; ++i) scanf("%lld%lld%lld", a + i, b + i, c + i);
  ++n, a[n] = c[n] = inf;
  for (int i(1); i <= n; ++i)
    sa[i] = sa[i - 1] + a[i], sb[i] = sb[i - 1] + b[i],
    sc[i] = sc[i - 1] + c[i];
  static long long f[N][N][2], g[N][N][2];
  memset(f, 0x3f, sizeof(f));
  memset(g, 0x3f, sizeof(g));
  for (int i(0); i <= t; ++i)
    f[0][i][0] = f[0][i][1] = g[0][i][0] = g[0][i][1] = 0;
  for (int p(1); p <= n; ++p)
    for (int s(0); s <= t; ++s)
      for (int z(0); z < 2; ++z) {
        static long long val, x, m;
        if (f[p - 1][s][z] != inf && z * a[p] + s * b[p] <= c[p]) {
          Min(f[p][s][z], f[p - 1][s][z]);
          val = (z * sa[p - 1] + s * sb[p - 1] + k - 1) / k;
          if (val * k <= z * sa[p] + s * sb[p]) Min(g[p][s][z], val);
        }
        for (int r(0); r < s; ++r)
          if (g[p][r][z] ^ inf) {
            m = z * sa[p] + r * sb[p] - k * g[p][r][z];
            x = (std::max(m + (s - r) * b[p] - c[p], 0ll) + k - 1) / k;
            if (x * k > m || f[p - 1][s - r][0] == inf) continue;
            Min(f[p][s][z], g[p][r][z] + x + f[p - 1][s - r][0]);
            val = x + ((s - r) * sb[p - 1] + k - 1) / k;
            if (val * k <= (s - r) * sb[p] + m)
              Min(g[p][s][z], g[p][r][z] + val);
          }
      }
  printf("%lld\n", f[n][t][1]);
  return 0;
}
