#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=200+10;
const ll inf=1e18;
ll a[maxn],b[maxn],c[maxn],sa[maxn],sb[maxn];
ll f[maxn][maxn][2],g[maxn][maxn][2];
inline ll Ceil(ll x,ll y){
	return (x+y-1)/y;
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("e.in","r",stdin);
	freopen("e.out","w",stdout);
#endif
	int n=read(),t=read(),m=read();
	REP(i,1,n) a[i]=read(),b[i]=read(),c[i]=read();
	++n;
	a[n]=c[n]=inf;
	REP(i,1,n) sb[i]=sb[i-1]+b[i],sa[i]=sa[i-1]+a[i];
	REP(i,1,n) REP(j,1,t) REP(u,0,1){
		f[i][j][u]=g[i][j][u]=inf;
		if(u*a[i]+(ll)j*b[i]<=c[i] && f[i-1][j][u]<inf){
			f[i][j][u]=f[i-1][j][u];
			ll cur=Ceil(j*sb[i-1]+u*sa[i-1],m);
			if(cur*m<=j*sb[i]+u*sa[i]) g[i][j][u]=cur;
			continue;
		}
		REP(k,0,j-1){
			if(g[i][k][u]>=inf || f[i-1][j-k][0]>=inf) continue;
			ll cur=u*a[i]+j*b[i]-(g[i][k][u]*m-u*sa[i-1]-k*sb[i-1]);
			if(cur<0) continue;
			ll res=Ceil(max(0ll,cur+(j-k)*b[i]-c[i]),m);
			if(res*m>cur) continue;
			chkmin(f[i][j][u],g[i][k][u]+res+f[i-1][j-k][0]);
			res+=Ceil((j-k)*sb[i-1],m);
			if(res*m>sb[i]*(j-k)+cur) continue;
			chkmin(g[i][j][u],g[i][k][u]+res);
		}
	}
	printf("%lld\n",f[n][t][1]);
	return 0;
}
