#region Header #!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools from queue import PriorityQueue import bisect import heapq def input(): return sys.stdin.readline()[:-1] sys.setrecursionlimit(1000000) #endregion # _INPUT = """3 3 2 1 # 1 2 2 # 2 1 2 # """ # sys.stdin = io.StringIO(_INPUT) def main(): Gx, Gy, N, F = map(int, input().split()) crystals = [] for _ in range(N): _x, _y, _c = map(int, input().split()) crystals.append((_x, _y, _c)) dp = [[[10**10 for _ in range(Gy+1)] for _ in range(Gx+1)] for _ in range(N+1)] dp[0][0][0] = 0 for n in range(N): for x in range(Gx+1): for y in range(Gy+1): dp[n+1][x][y] = min(dp[n+1][x][y], dp[n][x][y]) crystal = crystals[n] x1 = x + crystal[0] y1 = y + crystal[1] if x1 <= Gx and y1 <= Gy: dp[n+1][x1][y1] = min(dp[n+1][x1][y1], dp[n][x][y] + crystal[2]) cost_min = 10**10 for x in range(Gx+1): for y in range(Gy+1): d = (Gx - x) + (Gy - y) cost = dp[N][x][y] + F * d cost_min = min(cost_min, cost) print(cost_min) if __name__ == '__main__': main()