#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; #define INF 1000000000 struct ST { int x, y, c; }; int main(){ int Gx, Gy, N, F; cin >> Gx >> Gy >> N >> F; vector v; rep(i,N){ int x, y, c; cin >> x >> y >> c; v.push_back((ST){x,y,c}); } vector> cost(Gy+1, vector(Gx+1,INF)); cost[0][0] = 0; rep(y,cost.size()){ rep(x,cost[y].size()){ if(y+1> new_cost = cost; rep(y,cost.size()){ rep(x,cost[y].size()){ if(cost[y][x] != INF){ new_cost[y][x] = min(new_cost[y][x], cost[y][x]); if(x+v[i].x