#define REP(i,n) for(int i=0; i<(int)(n); i++) #include #include inline int getInt(){ int s; scanf("%d", &s); return s; } #include using namespace std; int dp[200][200][2]; const int _dx[] = {0,1,0,-1}; const int _dy[] = {-1,0,1,0}; #define IN(x,s,g) ((x) >= (s) && (x) < (g)) #define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h))) int main(){ const int n = getInt(); const int v = getInt(); const int ox = getInt() - 1; const int oy = getInt() - 1; vector > g(n, vector(n)); REP(i,n) REP(j,n) g[i][j] = getInt(); typedef pair, int> > data; priority_queue pq; auto cd = [](int hp, int x, int y, int o){ return data(hp, make_pair(make_pair(x, y), o)); }; pq.push(cd(v, 0, 0, 0)); while(pq.size()){ const data d = pq.top(); pq.pop(); const int h = d.first; const int x = d.second.first.first; const int y = d.second.first.second; const int o = d.second.second; if(dp[y][x][o]) continue; dp[y][x][o] = h; if(x == n - 1 && y == n - 1){ puts("YES"); return 0; } REP(i,4){ const int xx = x + _dx[i]; const int yy = y + _dy[i]; if(ISIN(xx, yy, n, n)){ const int hh = h * (ox == x && oy == y && o == 0 ? 2 : 1) - g[yy][xx]; const int oo = ox == x && oy == y ? 1 : o; if(dp[yy][xx][oo] != 0) continue; if(hh <= 0) continue; pq.push(cd(hh, xx, yy, oo)); } } } puts("NO"); return 0; }