#include "bits/stdc++.h" #define REP(i,n,N) for(int i=(n); i<(N); i++) #define RREP(i,n,N) for(int i=(N-1); i>=n; i--) #define CK(n,a,b) ((a)<=(n)&&(n)<(b)) #define ALL(v) (v).begin(),(v).end() #define p(s) cout<<(s)<> typedef long long ll; using namespace std; const int inf=1e9; int gx, gy, N, F; int dp[52][110][110]; vector x(110),y(110),c(110); int main() { cin>>gx>>gy>>N>>F; REP(i,0,N){ cin>>x[i]>>y[i]>>c[i]; } REP(i,0,N+1) REP(j,0,gy+1) REP(k,0,gx+1) dp[i][j][k]=inf; dp[0][0][0]=0; REP(i,0,N){ REP(Y,0,gy+1){ REP(X,0,gx+1){ dp[i+1][Y][X]=min(dp[i+1][Y][X], dp[i][Y][X]); if(Y+y[i]<=gy&&X+x[i]<=gx) dp[i+1][Y+y[i]][X+x[i]] = min(dp[i+1][Y+y[i]][X+x[i]], dp[i][Y][X]+c[i]); } } } int ans=inf; REP(i,0,gy+1){ REP(j,0,gx+1){ ans=min(ans,dp[N][i][j]+F*((gy-i)+(gx-j))); } } p(ans); return 0; }