R=xrange;I=lambda:map(int,raw_input().split()) W,H,N,F=I() dp=[[F*(i+j) for j in R(W+1)]for i in R(H+1)] for t in R(N): x,y,c = I() for i in R(H,y,-1): for j in R(W,x,-1): dp[i][j]=min(dp[i][j],dp[i-y][j-x]+c) print dp[H][W]