#include using namespace std; #define fst(t) std::get<0>(t) #define snd(t) std::get<1>(t) #define thd(t) std::get<2>(t) using ll = long long; using P = std::tuple; const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1}; int Gx, Gy, N, F; int Xs[100], Ys[100], Cs[100]; int dp[200][200][200]; int rec(int x, int y, int n){ if(x == Gx && y == Gy){ return 0; } if(dp[y][x][n] != -1){ return dp[y][x][n]; } // printf("%d, %d, %d\n", x, y, n); int res = (Gx - x + Gy - y) * F; //rec(x, y, n+1); for(int i=n;i Gx || ny > Gy){continue;} res = min(res, Cs[i] + rec(nx, ny, i+1)); } return dp[y][x][n] = res; } int main(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); memset(dp, -1, sizeof(dp)); std::cin >> Gx >> Gy >> N >> F; for(int i=0;i> Xs[i] >> Ys[i] >> Cs[i]; } std::cout << rec(0, 0, 0) << std::endl; }