#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmin(T &x, const T &y) {
  if (x > y) x = y;
}
const int N = 200 + 5;
int n, t, k, a[N], b[N], c[N], tmp[N][N];
long long f[N];
long long F(int t) {
  long long &ans = f[t];
  if (ans != -1) return ans;
  ans = 1e18;
  long long base = 0;
  int n = ::n, *a = tmp[t];
  for (int i = 1; i <= n; ++i) a[i] = b[i];
  while (1) {
    while (n && a[n] + long long(t) * b[n] <= c[n]) --n;
    if (!n) {
      chmin(ans, base);
      break;
    }
    long long sum = 0;
    for (int i = 1; i <= n - 1; ++i) sum += a[i];
    long long d =
        (sum + min(long long(a[n]), a[n] + long long(t) * b[n] - c[n])) / k;
    base += d;
    long long x = sum + a[n] - d * k;
    chmin(ans, F(t - 1) + base + (x > 0));
    for (int i = n; i >= 1; --i) x -= (a[i] = min(long long(a[i]), x));
    --t;
    for (int i = 1; i <= n; ++i)
      if ((a[i] += b[i]) > c[i]) goto End;
  }
End:;
  return ans;
}
int main() {
  cin >> n >> t >> k;
  for (int i = 1; i <= n; ++i) scanf("%d%d%d", a + i, b + i, c + i);
  if (!n) {
    puts("0");
    exit(0);
  }
  for (int i = 1; i <= t; ++i) f[i] = -1;
  long long base = 0, ans = 1e18;
  while (1) {
    while (n && a[n] + long long(t) * b[n] <= c[n]) --n;
    if (!n) {
      chmin(ans, base);
      break;
    }
    long long sum = 0;
    for (int i = 1; i <= n - 1; ++i) sum += a[i];
    long long d =
        (sum + min(long long(a[n]), a[n] + long long(t) * b[n] - c[n])) / k;
    base += d;
    long long x = sum + a[n] - d * k;
    chmin(ans, F(t - 1) + base + (x > 0));
    for (int i = n; i >= 1; --i) x -= (a[i] = min(long long(a[i]), x));
    --t;
    for (int i = 1; i <= n; ++i)
      if ((a[i] += b[i]) > c[i]) goto End;
  }
End:;
  cout << ans;
}
