#include using namespace std; #ifdef LOCAL_DEBUG #include "LOCAL_DEBUG.hpp" #endif #define int long long const int INF = 1LL << 60; signed main(){ int Gx, Gy, N, F; cin >> Gx >> Gy >> N >> F; static int dp[101][101][51]; fill(dp[0][0], dp[100][100] + 50, INF); dp[0][0][0] = 0; for(int i = 0; i < N; i++){ int x, y, c; cin >> x >> y >> c; for(int j = 0; j <= Gx; j++){ for(int k = 0; k <= Gy; k++){ dp[j][k][i+1] = min(dp[j][k][i+1], dp[j][k][i]); if(j + x <= Gx && k + y <= Gy){ dp[j + x][k + y][i+1] = min(dp[j + x][k + y][i+1], dp[j][k][i] + c); } } } for(int j = 0; j <= Gx; j++){ for(int k = 0; k <= Gy; k++){ if(j + 1 <= Gx){ dp[j + 1][k][i+1] = min(dp[j + 1][k][i+1], dp[j][k][i+1] + F); } if(k + 1 <= Gy){ dp[j][k + 1][i+1] = min(dp[j][k + 1][i+1], dp[j][k][i+1] + F); } } } } cout << dp[Gx][Gy][N] << endl; return 0; }