#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long inf = 2147383647;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;
mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>(
                chrono::high_resolution_clock::now().time_since_epoch())
                .count());
template <typename S, typename T>
void xmin(S& a, T const& b) {
  if (b < a) a = b;
}
template <typename S, typename T>
void xmax(S& a, T const& b) {
  if (b > a) a = b;
}
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
inline long long gcd(long long a, long long b) {
  a = ((a) < 0 ? -(a) : (a));
  b = ((b) < 0 ? -(b) : (b));
  while (b) {
    a = a % b;
    swap(a, b);
  }
  return a;
}
long long ext_gcd(long long A, long long B, long long* X, long long* Y) {
  long long x2, y2, x1, y1, x, y, r2, r1, q, r;
  x2 = 1;
  y2 = 0;
  x1 = 0;
  y1 = 1;
  for (r2 = A, r1 = B; r1 != 0;
       r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y) {
    q = r2 / r1;
    r = r2 % r1;
    x = x2 - (q * x1);
    y = y2 - (q * y1);
  }
  *X = x2;
  *Y = y2;
  return r2;
}
inline long long modInv(long long a, long long m) {
  long long x, y;
  ext_gcd(a, m, &x, &y);
  x %= m;
  if (x < 0) x += m;
  return x;
}
inline long long power(long long a, long long p) {
  long long res = 1, x = a;
  while (p) {
    if (p & 1) res = (res * x);
    x = (x * x);
    p >>= 1;
  }
  return res;
}
inline long long bigmod(long long a, long long p, long long m) {
  long long res = 1 % m, x = a % m;
  while (p) {
    if (p & 1) res = (res * x) % m;
    x = (x * x) % m;
    p >>= 1;
  }
  return res;
}
signed gen(int T) {
  auto get_rand = [&](int64_t l, int64_t r) {
    return uniform_int_distribution<int64_t>(l, r)(rng);
  };
  ofstream o("gen.txt");
  const int N = T;
  T = 1;
  o << T << "\n";
  for (int cas = 0; cas < T; ++cas) {
    o << "\n";
    int n = get_rand(1, N), t = get_rand(1, N), k = get_rand(1, N);
    o << n << ' ' << t << ' ' << k << "\n";
    for (long long i = (1); i <= (n); ++i) {
      int a = get_rand(0, N), b = get_rand(0, N),
          c = get_rand(((a) > (b) ? (a) : (b)), N);
      o << a << ' ' << b << ' ' << c << "\n";
    }
  }
  o << endl;
  o.close();
  return 0;
}
const int N = 200;
const long long INF = inf << 30;
long long dp[N + 2][N + 1][2], dp2[N + 2][N + 1][2], A[N + 2], B[N + 2],
    C[N + 2], SA[N + 2], SB[N + 2], SC[N + 2];
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  int n, t, K;
  cin >> n >> t >> K;
  for (long long 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];
    SC[i] = SC[i - 1] + C[i];
  }
  A[n + 1] = INF;
  B[n + 1] = 0;
  C[n + 1] = 2 * INF;
  SA[n + 1] = SA[n] + A[n + 1];
  SB[n + 1] = SB[n] + B[n + 1];
  SC[n + 1] = SC[n] + C[n + 1];
  memset(dp, -1, sizeof(dp));
  memset(dp2, -1, sizeof(dp2));
  for (long long i = (0); i <= (n + 1); ++i) {
    for (long long j = (0); j <= (t); ++j) {
      for (long long k = (0); k <= (1); ++k) {
        if (i == 0) {
          dp[i][j][k] = dp2[i][j][k] = 0;
        } else {
          if (k * A[i] + j * B[i] <= C[i]) {
            if (dp[i - 1][j][k] != -1) {
              dp[i][j][k] = dp[i - 1][j][k];
              long long val = (k * SA[i - 1] + j * SB[i - 1] + K - 1) / K;
              if (val * K <= k * SA[i] + j * SB[i]) {
                dp2[i][j][k] = val;
              }
            }
          }
          for (long long jj = (0); jj <= (j - 1); ++jj) {
            long long aux = dp2[i][jj][k];
            if (aux != -1) {
              long long rem = k * SA[i] + jj * SB[i] - K * aux,
                        val = (((0) > (rem + (j - jj) * B[i] - C[i])
                                    ? (0)
                                    : (rem + (j - jj) * B[i] - C[i])) +
                               K - 1) /
                              K;
              if (val * K <= rem) {
                if (dp[i - 1][j - jj][0] != -1) {
                  long long newValue = aux + val + dp[i - 1][j - jj][0];
                  if (dp[i][j][k] == -1 || dp[i][j][k] > newValue) {
                    dp[i][j][k] = newValue;
                  }
                }
                long long x = ((j - jj) * SB[i - 1] + K - 1) / K;
                if (x * K <= (j - jj) * SB[i] + rem - val * K) {
                  long long newValue = aux + val + x;
                  if (dp2[i][j][k] == -1 || dp2[i][j][k] > newValue) {
                    dp2[i][j][k] = newValue;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  long long res = dp[n + 1][t][1];
  cout << res << "\n";
  return 0;
}
