#include using namespace std; #define FOR(i, n) for(int i = 0; i < (n); i++) #define MEM(a, x) memset(a, x, sizeof(a)) #define ALL(a) a.begin(), a.end() #define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) typedef long long ll; typedef pair P; int gx, gy, n, f, dp[105][105]; int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin >> gx >> gy >> n >> f; FOR(i, gx+1) FOR(j, gy+1) dp[i][j] = (i+j)*f; FOR(cnt, n) { int x, y, c; cin >> x >> y >> c; dp[x][y] = min(dp[x][y], c); for (int i = x; i <= gx; i++) { for (int j = y; j <= gy; j++) { dp[i][j] = min(dp[i-x][j-y]+dp[x][y], dp[i][j]); } } } cout << dp[gx][gy] << endl; return 0; }