#include using namespace std; using ll = long long; ll memo[81][81][15000]; int vis[81][81][15000]; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll ans = 1e18; ll n,m,k,t; cin>>n>>m>>k>>t; vector>> use(n,vector>(m)); for(int i = 0;i>a>>b>>c>>d; a--;b--; use[a][b] = make_pair(c,d); } using dat = pair>; priority_queue,vector>,greater>> que; que.push(make_pair(0,make_pair(0,make_pair(0,0)))); int dx[] = {1,-1,0,0}; int dy[] = {0,0,1,-1}; for(int i = 0;it) continue; ans = min(ans,now.first); continue; } for(int k = 0;k<4;k++){ int nni = ni + dx[k]; int nnj = nj + dy[k]; if(nni<0||nnj<0||nni>=n||nnj>=m) continue; ll nxt = now.second.first; nxt++; ll cost = now.first; if(use[nni][nnj].first!=0){ nxt++; nxt -= use[nni][nnj].first; cost += use[nni][nnj].second; } if(nxt<=-7000) nxt = -7000; if(nxt>=7000) nxt = 7000; dat will = make_pair(nxt,make_pair(nni,nnj)); if(memo[nni][nnj][nxt+7000]<=cost) continue; memo[nni][nnj][nxt+7000]; que.push(make_pair(cost,will)); } } if(ans==1e18) ans = -1; cout<