#include <bits/stdc++.h>
using namespace std;
const int N = 200 + 11;
long long a[N], b[N], c[N], sa[N], sb[N], sc[N];
long long d[N][N][2], g[N][N][2];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, t, k;
  cin >> n >> t >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  n++;
  a[n] = 2e18;
  b[n] = 0;
  c[n] = 2e18;
  for (int i = 1; i <= n; i++) {
    sa[i] = sa[i - 1] + a[i];
    sb[i] = sb[i - 1] + b[i];
    sc[i] = sc[i - 1] + c[i];
  }
  for (int p = 1; p <= n; p++)
    for (int s = 0; s <= t; s++)
      for (int z = 0; z <= 1; z++) {
        d[p][s][z] = 2e18;
        g[p][s][z] = 2e18;
        if (d[p - 1][s][z] < 2e18 && a[p] * 1ll * z + b[p] * 1ll * s <= c[p]) {
          d[p][s][z] = d[p - 1][s][z];
          long long d = (z * 1ll * sa[p - 1] + s * 1ll * sb[p - 1] + k - 1) / k;
          if (d * k <= z * 1ll * sa[p] + s * 1ll * sb[p]) g[p][s][z] = d;
        }
        for (int r = 0; r < s; r++)
          if (g[p][r][z] < 2e18) {
            long long m =
                z * 1ll * sa[p] + r * 1ll * sb[p] - k * 1ll * g[p][r][z];
            long long x = (max(m + (s - r) * b[p] - c[p], 0ll) + k - 1) / k;
            m -= x * k;
            if (m >= 0 && d[p - 1][s - r][0] < 2e18)
              d[p][s][z] = min(d[p][s][z], g[p][r][z] + x + d[p - 1][s - r][0]);
            long long d = ((s - r) * sb[p - 1] + k - 1) / k;
            if (m >= 0 && d * k <= m + (s - r) * 1ll * sb[p])
              g[p][s][z] = min(g[p][s][z], g[p][r][z] + x + d);
          }
      }
  cout << d[n][t][1];
}
