#include <bits/stdc++.h>
using namespace std;
long long a[300], b[300], c[300], sa[300], sb[300];
long long f[300][300][2], g[300][300][2];
int main() {
  int n, t, k;
  cin >> n >> t >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld%lld", &a[i], &b[i], &c[i]);
    sa[i] = sa[i - 1] + a[i];
    sb[i] = sb[i - 1] + b[i];
  }
  n++;
  a[n] = c[n] = (1LL << 50);
  sa[n] = a[n] + sa[n - 1];
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= t; j++) {
      for (int z = 0; z <= 1; z++) {
        f[i][j][z] = g[i][j][z] = (1LL << 50);
        if (z * a[i] + j * b[i] <= c[i] && f[i - 1][j][z] != (1LL << 50)) {
          f[i][j][z] = f[i - 1][j][z];
          long long v = ((z * sa[i - 1] + j * sb[i - 1]) + k - 1) / k;
          if (v * k <= z * sa[i] + j * sb[i]) g[i][j][z] = v;
        }
        for (int r = 0; r < j; r++) {
          if (g[i][r][z] == (1LL << 50)) continue;
          long long re = sa[i] * z + sb[i] * r - g[i][r][z] * k;
          long long v = (max(0LL, (j - r) * b[i] + re - c[i]) + k - 1) / k;
          if (v * k <= re && f[i - 1][j - r][0] != (1LL << 50)) {
            f[i][j][z] = min(f[i][j][z], g[i][r][z] + v + f[i - 1][j - r][0]);
            long long u = (sb[i - 1] * (j - r) + k - 1) / k;
            if (u * k <= sb[i] * (j - r) + re - v * k)
              g[i][j][z] = min(g[i][j][z], g[i][r][z] + v + u);
          }
        }
      }
    }
  }
  cout << f[n][t][1] << endl;
  return 0;
}
