#include <bits/stdc++.h>
using namespace std;
const int _ = 200 + 7;
const long long inf = 1e15;
int n, T, K;
long long a[_], b[_], c[_], sa[_], sb[_], d[_][_][2], g[_][_][2];
long long Ceil(long long x, long long y) { return x % y ? x / y + 1 : x / y; }
void upd(long long &x, long long y) { x = min(x, y); }
int main() {
  cin >> n >> T >> K;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i] >> b[i] >> c[i];
    sa[i] = sa[i - 1] + a[i];
    sb[i] = sb[i - 1] + b[i];
  }
  a[++n] = inf, c[n] = inf;
  sa[n] = sa[n - 1] + a[n];
  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] = g[p][s][z] = inf;
  for (int p = 1; p <= n; ++p)
    for (int s = 0; s <= T; ++s)
      for (int z = 0; z <= 1; ++z) {
        if (z * a[p] + s * b[p] <= c[p] and d[p - 1][s][z] != inf) {
          upd(d[p][s][z], d[p - 1][s][z]);
          long long num = Ceil(z * sa[p - 1] + s * sb[p - 1], K);
          if (num * K <= z * sa[p] + s * sb[p]) upd(g[p][s][z], num);
        }
        for (int r = 0; r < s; ++r)
          if (g[p][r][z] != inf and d[p - 1][s - r][0] != inf) {
            long long m = z * sa[p] + r * sb[p] - K * g[p][r][z];
            long long x = Ceil(max(0ll, m + (s - r) * b[p] - c[p]), K);
            if (K * x <= m) {
              upd(d[p][s][z], g[p][r][z] + x + d[p - 1][s - r][0]);
              long long num = Ceil((s - r) * sb[p - 1], K);
              if (num * K <= m - K * x + (s - r) * sb[p])
                upd(g[p][s][z], g[p][r][z] + x + num);
            }
          }
        upd(d[p][s][z], g[p][s][z]);
      }
  cout << d[n][T][1] << endl;
  return 0;
}
