#include <bits/stdc++.h>
using namespace std;
const int N = 310;
const long long inf = 4e18;
long long f[N][N][2], g[N][N][2], a[N], b[N], c[N], sa[N], sb[N];
int n, t, K;
long long up(long long x) {
  if (x <= 0) return 0;
  return (x + K - 1) / K;
}
int main() {
  scanf("%d%d%d", &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;
  for (int i = 1; i <= n; i++) sa[i] = sa[i - 1] + a[i];
  for (int i = 1; i <= n; i++) sb[i] = sb[i - 1] + b[i];
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= t; j++)
      for (int l = 0; l < 2; l++) {
        f[i][j][l] = g[i][j][l] = inf;
        if (c[i] >= j * b[i] + l * a[i] && f[i - 1][j][l] != inf) {
          f[i][j][l] = f[i - 1][j][l];
          g[i][j][l] = up(sa[i - 1] * l + sb[i - 1] * j);
          if (g[i][j][l] * K > sa[i] * l + sb[i] * j) g[i][j][l] = inf;
        }
        for (int k = 0; k < j; k++)
          if (g[i][k][l] != inf) {
            long long lft = sa[i] * l + sb[i] * k - g[i][k][l] * K,
                      ct = up(b[i] * (j - k) - c[i] + lft);
            if ((g[i][k][l] + ct) * K > sa[i] * l + sb[i] * k ||
                f[i - 1][j - k][0] == inf)
              continue;
            f[i][j][l] = min(f[i][j][l], g[i][k][l] + ct + f[i - 1][j - k][0]);
            long long d = up(sb[i - 1] * (j - k));
            if ((g[i][k][l] + ct + d) * K <= sa[i] * l + sb[i] * j)
              g[i][j][l] = min(g[i][j][l], g[i][k][l] + ct + d);
          }
      }
  printf("%lld\n", f[n][t][1]);
  return 0;
}
