#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() template inline bool chmax(A &a, B b) { if (a inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; } typedef unsigned long long ull; typedef long long ll; typedef pair pii; typedef pair pll; const ll INF = 1ll<<29; const ll MOD = 1000000007; const double EPS = 1e-10; int gx, gy, n, f; int x[50], y[50], c[50]; int dp[101][101]; int main() { cin >> gx >> gy >> n >> f; REP(i, n) scanf("%d %d %d", x + i, y + i, c + i); fill(dp[0], dp[101], INF); dp[0][0] = 0; REP(i, gy + 1) REP(j, gx + 1) { if (i > 0) chmin(dp[i][j], dp[i - 1][j] + f); if (j > 0) chmin(dp[i][j], dp[i][j - 1] + f); } REP(t, n) { for (int i = gy; i >= y[t]; i--) { for (int j = gx; j >= x[t]; j--) { chmin(dp[i][j], dp[i - y[t]][j - x[t]] + c[t]); } } } cout << dp[gy][gx] << endl; return 0; }