#include <bits/stdc++.h>
using namespace std;
const int N = 205;
int n, t, k;
long long a[N], b[N], c[N];
long long sa[N], sb[N];
long long f[N][N][2];
long long g[N][N][2];
int main() {
  scanf("%d%d%d", &n, &t, &k);
  for (int i = (int)(1); i <= (int)(n); i++)
    scanf("%lld%lld%lld", &a[i], &b[i], &c[i]);
  ++n;
  a[n] = c[n] = (1ll << 60);
  for (int i = (int)(1); i <= (int)(n); i++)
    sa[i] = sa[i - 1] + a[i], sb[i] = sb[i - 1] + b[i];
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(0); j <= (int)(t); j++)
      for (int fl = (int)(0); fl <= (int)(1); fl++) {
        f[i][j][fl] = g[i][j][fl] = (1ll << 60);
        if (1ll * j * b[i] + 1ll * fl * a[i] <= c[i] &&
            f[i - 1][j][fl] != (1ll << 60)) {
          f[i][j][fl] = f[i - 1][j][fl];
          long long v =
              (1ll * fl * sa[i - 1] + 1ll * j * sb[i - 1] + k - 1) / k;
          if (v * k <= 1ll * fl * sa[i] + 1ll * j * sb[i]) g[i][j][fl] = v;
        }
        for (int l = (int)(0); l <= (int)(j - 1); l++)
          if (g[i][l][fl] < (1ll << 60)) {
            long long v1 =
                1ll * fl * sa[i] + 1ll * l * sb[i] - 1ll * k * g[i][l][fl];
            long long v2 =
                (max(v1 + 1ll * (j - l) * b[i] - c[i], 0ll) + k - 1) / k;
            if (1ll * v2 * k <= v1 && f[i - 1][j - l][0] < (1ll << 60)) {
              f[i][j][fl] =
                  min(f[i][j][fl], g[i][l][fl] + v2 + f[i - 1][j - l][0]);
              long long v = (1ll * (j - l) * sb[i - 1] + k - 1) / k;
              if (v * k <= (j - l) * sb[i] + v1 - v2 * k)
                g[i][j][fl] = min(g[i][j][fl], g[i][l][fl] + v2 + v);
            }
          }
      }
  printf("%lld\n", f[n][t][1]);
}
