#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 10000000 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(i,N){ vector> new_cost = cost; rep(y,cost.size()){ rep(x,cost[y].size()){ if(cost[y][x] != INF){ if(x+v[i].x que; que.push((ST){0,0,0}); while(!que.empty()){ ST st = que.front(); que.pop(); if(st.y+1