#include #include #include #include using namespace std; int N,M,K,T; int C[80][80],D[80][80]; long dp[80][80][320]; const int d[5]={0,1,0,-1}; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin>>N>>M>>K>>T; for(int i=0;i>a>>b>>c>>d; a--,b--; C[a][b]=c; D[a][b]=d; } if((N-1)+(M-1)<=T) { cout<<0< > >Q; Q.push(make_pair(0,make_pair(0,off))); long ans=1e18; while(!Q.empty()) { long c=-Q.top().first; int xy=Q.top().second.first,t=Q.top().second.second; Q.pop(); int x=xy/M,y=xy%M; if(dp[x][y][t]nc) { dp[x][y][nt]=nc; Q.push(make_pair(-nc,make_pair(x*M+y,nt))); } } for(int r=0;r<4;r++) { int tx=x+d[r],ty=y+d[r+1]; if(tx<0||ty<0||tx>=N||ty>=M||t+1>off*2)continue; if(dp[tx][ty][t+1]>c) { dp[tx][ty][t+1]=c; Q.push(make_pair(-c,make_pair(tx*M+ty,t+1))); } } } if(ans==(long)1e18)ans=-1; cout<