#include using namespace std; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define rep(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define ALL(a) (a).begin(),(a).end() #define all(a) (a).begin(),(a).end() #define EXIST(s,e) (find(all(s),(e))!=(s).end()) #define exist(s,e) (find(all(s),(e))!=(s).end()) #define FINDi(s,e) distance((s).begin(),find(all(s),(e))) #define INF (1<<25) #define ll long long #define VS vector #define VI vector #define vi vector #define VI2 vector> #define vi2 vector> #define v2Resize(s,x,y) s.resize(x); REP(i,s.size()) s[i].resize(y); #define v2Fill(s,v) REP(v2filliiiiiii,s.size()) fill(all(s[v2filliiiiiii]),v); #define Pii pair #define P pair; #define in1(x,m) REP(in1iiiiiiiiiiii,m){int tmpForIn1Macrofjaio; cin>>tmpForIn1Macrofjaio; x.push_back(tmpForIn1Macrofjaio);} #define in2(v2,x,y) REP(in2iiiiiiiiiiiiii,x) REP(in2jjjjjjjjj,y) cin>>v2[in2iiiiiiiiiiiiii][in2jjjjjjjjj]; #define OUT2(v2) REP(out2iiiiiiiii,v2.size()){ REP(out2jjjjjjjjjjj,v2[out2iiiiiiiii].size()){ cout< PP; void dijkstra(int y, int x) { priority_queue, greater> que; rep(i, n) rep(j, n)dist[i][j] = INF; dist[y][x] = 0; que.push(make_pair(0,Pii(y, x))); while (!que.empty()) { int c = que.top().first; auto now = que.top().second; que.pop(); rep(i,4) { int ny = now.first + dy4[i], nx = now.second + dx4[i]; if (!(0 <= ny && ny < n && 0 <= nx && nx < n))continue; if (dist[ny][nx] <= c + L[ny][nx])continue; dist[ny][nx] = c + L[ny][nx]; que.push(make_pair(dist[ny][nx], Pii(ny, nx))); } } } int main() { cin >> n >> V >> ox >> oy; ox--; oy--; rep(y, n) rep(x, n)cin >> L[y][x]; dijkstra(0, 0); if (dist[n - 1][n - 1] < V) { cout << "YES" << endl; return 0; } if(ox==-1&&oy==-1) { cout << "NO" << endl; } int t = (V - dist[oy][ox]) * 2; dijkstra(oy, ox); if(t-dist[n-1][n-1]>0) { cout << "YES" << endl; }else { cout << "NO" << endl; } return 0; }