#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 201;
const int H = 201;
int n, t;
long long z;
long long a[N], b[N], c[N];
array<long long, H> c1[N], r1[N], c2[N], r2[N];
long long d[N];
void compute(int i, long long& c, long long& r) {
  c = 0, r = 0;
  long long s = 0;
  for (int k = 1; k < i; k++) s += d[k];
  c = (s + z - 1) / z;
  s = (z - s % z) % z;
  r = max(0LL, d[i] - s);
}
void solve(int i, array<long long, H>& ci, array<long long, H>& ri) {
  long long q, r;
  compute(i, q, r);
  ci[0] = q;
  ri[0] = r;
  long long cq = 0, cr = 0;
  for (int j = 1; j <= t; j++) {
    int bad = 0;
    for (int j = 1; j <= i; j++) {
      if (d[j] + b[j] > c[j]) bad = j;
    }
    if (bad != 0) {
      long long s = 0;
      for (int k = 1; k < bad; k++) {
        s += d[k];
        d[k] = 0;
      }
      s += d[bad] + b[bad] - c[bad];
      d[bad] = c[bad] - b[bad];
      cq += (s + z - 1) / z;
      s = (z - s % z) % z;
      for (int k = bad; k <= i; k++) {
        long long w = min(s, d[k]);
        d[k] -= w;
        s -= w;
      }
    }
    for (int j = 1; j <= i; j++) d[j] += b[j];
    compute(i, q, r);
    ci[j] += cq + q;
    ri[j] = r;
  }
}
long long dp[N][H], dp2[N][H];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> t >> z;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int k = 1; k <= i; k++) d[k] = a[k];
    solve(i, c1[i], r1[i]);
    for (int k = 1; k <= i; k++) d[k] = 0;
    solve(i, c2[i], r2[i]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= t; j++) {
      dp2[i][j] = 1e18;
      if (j * b[i] <= c[i]) {
        dp2[i][j] = dp2[i - 1][j];
        continue;
      }
      for (int p = 0; p <= j; p++) {
        if ((j - p) * b[i] > c[i]) continue;
        long long x = c[i] - (j - p) * b[i];
        long long f = max(0LL, (r2[i][p] - x + z - 1) / z);
        dp2[i][j] = min(dp2[i][j], c2[i][p] + f + dp2[i - 1][j - p]);
      }
      for (int p = 1; p <= j; p++) {
        long long x = 0;
        long long f = max(0LL, (r2[i][p] - x + z - 1) / z);
        dp2[i][j] = min(dp2[i][j], c2[i][p] + f + dp2[i][j - p]);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= t; j++) {
      dp[i][j] = 1e18;
      if (a[i] + j * b[i] <= c[i]) {
        dp[i][j] = dp[i - 1][j];
        continue;
      }
      for (int p = 0; p <= j; p++) {
        if ((j - p) * b[i] > c[i]) continue;
        long long x = c[i] - (j - p) * b[i];
        long long f = max(0LL, (r1[i][p] - x + z - 1) / z);
        dp[i][j] = min(dp[i][j], c1[i][p] + f + dp2[i - 1][j - p]);
      }
      for (int p = 1; p <= j; p++) {
        long long x = 0;
        long long f = max(0LL, (r1[i][p] - x + z - 1) / z);
        dp[i][j] = min(dp[i][j], c1[i][p] + f + dp2[i][j - p]);
      }
    }
  }
  cout << dp[n][t] << '\n';
}
