#include <bits/stdc++.h>
using namespace std;
long long a[205], b[205], c[205], suma[205], sumb[205];
long long f[2][205][205], g[2][205][205];
void dp1(int n, int m, int k) {
  for (int i = 1; i <= n; i++) f[0][i][0] = g[0][i][0] = 0;
  for (int i = 0; i <= m; i++) f[0][0][i] = g[0][0][i] = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (f[0][i - 1][j] != 0x3f3f3f3f3f3f3f3fLL && b[i] * j <= c[i]) {
        f[0][i][j] = f[0][i - 1][j];
        long long t = (sumb[i - 1] * j + k - 1) / k;
        if (k * t <= sumb[i] * j) g[0][i][j] = t;
      } else {
        for (int l = 0; l < j; l++) {
          if (g[0][i][l] == 0x3f3f3f3f3f3f3f3fLL) continue;
          long long s = sumb[i] * l - k * g[0][i][l];
          long long t = (max(0LL, s + b[i] * (j - l) - c[i]) + k - 1) / k;
          if (k * t <= s && f[0][i - 1][j - l] != 0x3f3f3f3f3f3f3f3fLL) {
            f[0][i][j] = min(f[0][i][j], g[0][i][l] + t + f[0][i - 1][j - l]);
            long long t2 = (sumb[i - 1] * (j - l) + k - 1) / k;
            if (k * t2 <= s - k * t + sumb[i] * (j - l))
              g[0][i][j] = min(g[0][i][j], g[0][i][l] + t + t2);
          }
        }
      }
}
void dp2(int n, int m, int k) {
  for (int i = 0; i <= m; i++) f[1][0][i] = g[1][0][i] = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= m; j++)
      if (f[1][i - 1][j] != 0x3f3f3f3f3f3f3f3fLL && a[i] + b[i] * j <= c[i]) {
        f[1][i][j] = f[1][i - 1][j];
        long long t = (suma[i - 1] + sumb[i - 1] * j + k - 1) / k;
        if (k * t <= suma[i] + sumb[i] * j) g[1][i][j] = t;
      } else {
        for (int l = 0; l < j; l++) {
          if (g[1][i][l] == 0x3f3f3f3f3f3f3f3fLL) continue;
          long long s = suma[i] + sumb[i] * l - k * g[1][i][l];
          long long t = (max(0LL, s + b[i] * (j - l) - c[i]) + k - 1) / k;
          if (k * t <= s && f[0][i - 1][j - l] != 0x3f3f3f3f3f3f3f3fLL) {
            f[1][i][j] = min(f[1][i][j], g[1][i][l] + t + f[0][i - 1][j - l]);
            long long t2 = (sumb[i - 1] * (j - l) + k - 1) / k;
            if (k * t2 <= s - k * t + sumb[i] * (j - l))
              g[1][i][j] = min(g[1][i][j], g[1][i][l] + t + t2);
          }
        }
      }
}
int main() {
  memset(f, 0x3f, sizeof(f));
  memset(g, 0x3f, sizeof(g));
  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]);
  a[n + 1] = 0x3f3f3f3fLL;
  b[n + 1] = 0x3f3f3f3fLL * (n + 1);
  c[n + 1] = 0x3f3f3f3fLL * (n + 1) * (m + 1);
  for (int i = 1; i <= n + 1; i++) {
    suma[i] = suma[i - 1] + a[i];
    sumb[i] = sumb[i - 1] + b[i];
  }
  dp1(n + 1, m, k);
  dp2(n + 1, m, k);
  printf("%lld\n", f[1][n + 1][m]);
  return 0;
}
