#include <bits/stdc++.h>
const long long inf = 1e18;
using namespace std;
int n, t, K, a[210], b[210];
long long pa[210], pb[210], c[210], f[210][210][2], g[210][210][2], tmp, nw, nd;
int main() {
  scanf("%d%d%d", &n, &t, &K);
  for (int i = 1; i <= n; i++) scanf("%d%d%lld", &a[i], &b[i], &c[i]);
  c[++n] = 1e18, a[n] = b[n] = 2e9;
  for (int i = 1; i <= n; i++)
    pa[i] = pa[i - 1] + a[i], pb[i] = pb[i - 1] + b[i];
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= t; j++)
      f[i][j][0] = f[i][j][1] = g[i][j][0] = g[i][j][1] = inf;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= t; j++) {
      for (int k = 0; k < 2; k++) {
        if (k * a[i] + 1ll * j * b[i] <= c[i] && f[i - 1][j][k] < inf) {
          f[i][j][k] = min(f[i][j][k], f[i - 1][j][k]);
          tmp = (k * pa[i - 1] + j * pb[i - 1] + K - 1) / K;
          if (tmp * K <= k * pa[i] + j * pb[i])
            g[i][j][k] = min(g[i][j][k], tmp);
        }
        for (int r = 0; r < j; r++)
          if (g[i][r][k] < inf) {
            nw = k * pa[i] + r * pb[i] - g[i][r][k] * K;
            nd = (max(0ll, nw + 1ll * (j - r) * b[i] - c[i]) + K - 1) / K;
            if (nd * K <= nw && f[i - 1][j - r][0] < inf) {
              f[i][j][k] =
                  min(f[i][j][k], f[i - 1][j - r][0] + g[i][r][k] + nd);
              tmp = ((j - r) * pb[i - 1] + K - 1) / K;
              if (tmp * K <= (j - r) * pb[i] + nw - nd * K)
                g[i][j][k] = min(g[i][j][k], g[i][r][k] + nd + tmp);
            }
          }
      }
    }
  }
  printf("%lld\n", f[n][t][1]);
}
