#include #include #include using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n,v; cin>>n>>v; vector>> dp(n,vector>(n,vector(v+1,1e9))); int si,sj,gi,gj; cin>>si>>sj>>gi>>gj; si--;sj--;gi--;gj--; swap(si,sj); swap(gi,gj); dp[si][sj][v] = 0; vector,int>> que; int dx[] = {1,-1,0,0}; int dy[] = {0,0,1,-1}; vector> a(n,vector(n)); for(int i = 0;i>a[i][j]; que.push_back(make_pair(make_pair(si,sj),v)); for(int i = 0;i=n||nnj>=n) continue; int nxt = kk - a[nni][nnj]; if(nxt<=0) continue; if(dp[nni][nnj][nxt]<=dp[ni][nj][kk]+1) continue; dp[nni][nnj][nxt] = dp[ni][nj][kk] + 1; que.push_back({{nni,nnj},nxt}); } } cout<<-1<