#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; #define INF 100000000 int main(){ int gx, gy, N, F; cin >> gx >> gy >> N >> F; vector x(N), y(N), c(N); rep(i,N){ cin >> x[i] >> y[i] >> c[i]; } vector> dp(gy+1,vector(gx+1,INF)); rep(yy,gy+1){ rep(xx,gx+1){ dp[yy][xx] = F * (yy+xx); } } rep(i,N){ for(int yy=gy; yy>=0; yy--){ for(int xx=gx; xx>=0; xx--){ if(yy-y[i]>=0 && xx-x[i]>=0){ dp[yy][xx] = min(dp[yy][xx], dp[yy-y[i]][xx-x[i]] + c[i]); } } } } cout << dp[gy][gx] << endl; return 0; }