#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15;
long long n, t, k;
long long a[305], b[305], c[305];
long long sa[305], sb[305], sc[305];
long long d[305][305][2], g[305][305][2];
int main() {
  scanf("%lld%lld%lld", &n, &t, &k);
  for (int i = 1; i <= n; ++i) scanf("%lld%lld%lld", &a[i], &b[i], &c[i]);
  ++n;
  a[n] = c[n] = inf;
  b[n] = 0;
  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];
  for (int i = 0; i <= n + 1; ++i)
    for (int j = 0; j <= t; ++j)
      for (int p = 0; p <= 1; ++p) d[i][j][p] = g[i][j][p] = inf;
  for (int p = 0; p <= n + 1; ++p)
    for (int s = 0; s <= t; ++s)
      for (int z = 0; z <= 1; ++z) {
        if (d[p - 1][s][z] != inf && z * a[p] + b[p] * s <= c[p]) {
          long long val = (z * sa[p - 1] + s * sb[p - 1] + k - 1) / k;
          d[p][s][z] = min(d[p][s][z], d[p - 1][s][z]);
          if (val * k <= z * sa[p] + s * sb[p])
            g[p][s][z] = min(g[p][s][z], val);
        }
        for (int r = 0; r < s; ++r) {
          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 (g[p][r][z] == inf || x * k > m || d[p - 1][s - r][0] == inf)
            continue;
          long long Val = ((s - r) * sb[p - 1] + k - 1) / k;
          d[p][s][z] = min(d[p][s][z], g[p][r][z] + x + d[p - 1][s - r][0]);
          g[p][s][z] = min(g[p][s][z], g[p][r][z] + x + Val);
        }
      }
  printf("%lld\n", d[n + 1][t][1]);
  return 0;
}
