#include #include template std::vector vec(int len, T elem) { return std::vector(len, elem); } constexpr int INF = 1 << 30; void solve() { int h, w, n, f; std::cin >> h >> w >> n >> f; auto cost = vec(h + 1, vec(w + 1, INF)); cost[0][0] = 0; while (n--) { int dx, dy, c; std::cin >> dx >> dy >> c; for (int x = h; x >= dx; --x) { for (int y = w; y >= dy; --y) { cost[x][y] = std::min(cost[x][y], cost[x - dx][y - dy] + c); } } } int ans = INF; for (int x = 0; x <= h; ++x) { for (int y = 0; y <= w; ++y) { ans = std::min(ans, cost[x][y] + (h - x + w - y) * f); } } std::cout << ans << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }