#include <bits/stdc++.h>
using ll = long long;
ll F[205][205][2], G[205][205][2];
ll a[205], b[205], c[205], sum_a[205], sum_b[205];
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++) scanf("%lld%lld%lld", a + i, b + i, c + i);
  n++;
  a[n] = c[n] = 1e18;
  for (int i = 1; i <= n; i++) {
    sum_a[i] = sum_a[i - 1] + a[i];
    sum_b[i] = sum_b[i - 1] + b[i];
  }
  memset(F, 0x3f, sizeof(F));
  memset(G, 0x3f, sizeof(G));
  memset(F[0], 0, sizeof(F[0]));
  memset(G[0], 0, sizeof(G[0]));
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      for (int x = 0; x < 2; x++) {
        if (x * a[i] + j * b[i] <= c[i] && F[i - 1][j][x] < 1e18) {
          F[i][j][x] = F[i - 1][j][x];
          ll val = (x * sum_a[i - 1] + j * sum_b[i - 1] + k - 1) / k;
          if (val * k <= x * sum_a[i] + j * sum_b[i]) G[i][j][x] = val;
        }
        for (int lst = 0; lst < j; lst++) {
          if (G[i][lst][x] >= 1e18) continue;
          ll val = x * sum_a[i] + lst * sum_b[i] - G[i][lst][x] * k;
          ll w = (std::max<ll>(val + (j - lst) * b[i] - c[i], 0) + k - 1) / k;
          if (w * k > val || F[i - 1][j - lst][0] >= 1e18) continue;
          F[i][j][x] =
              std::min(F[i][j][x], G[i][lst][x] + F[i - 1][j - lst][0] + w);
          ll t = ((j - lst) * sum_b[i - 1] + k - 1) / k;
          if (t * k <= (j - lst) * sum_b[i] + val - w * k)
            G[i][j][x] = std::min(G[i][j][x], G[i][lst][x] + w + t);
        }
      }
    }
  }
  printf("%lld\n", F[n][m][1]);
  return 0;
}
