#include #include #include #include #include #include #include using namespace std; template using pq = priority_queue, greater>; int main(){ bool ok=0; int N, V, h, w, oh, ow, alt, d, nh, nw; cin >> N >> V >> oh >> ow; oh--; ow--; pq> que; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; vector> dist(N, vector(N, 1e9)); vector> visit(N, vector(N)); vector> field(N, vector(N)); for (int i=0; i < N; i++){ for (int j=0; j> field[i][j]; } dist[0][0] = field[0][0]; que.push({field[0][0], 0, 0}); while(!que.empty()){ tie(d, h, w) = que.top(); que.pop(); if (visit[h][w]) continue; visit[h][w] = 1; for (int dir=0; dir < 4; dir++){ nh = h + dx[dir]; nw = w + dy[dir]; if (nh < 0 || nh >= N || nw < 0 || nw >= N) continue; alt = dist[h][w] + field[nh][nw]; if (alt < dist[nh][nw]){ dist[nh][nw] = alt; que.push({dist[nh][nw], nh, nw}); } } } if (dist[N-1][N-1] < V) ok = 1; for (int i=0; i= 0 && oh < N && ow >= 0 && ow < N){ dist[oh][ow] = field[oh][ow]; que.push({field[oh][ow], oh, ow}); while(!que.empty()){ tie(d, h, w) = que.top(); que.pop(); if (visit[h][w]) continue; visit[h][w] = 1; for (int dir=0; dir < 4; dir++){ nh = h + dx[dir]; nw = w + dy[dir]; if (nh < 0 || nh >= N || nw < 0 || nw >= N) continue; alt = dist[h][w] + field[nh][nw]; if (alt < dist[nh][nw]){ dist[nh][nw] = alt; que.push({dist[nh][nw], nh, nw}); } } } if (dist[0][0] < V && dist[N-1][N-1]-field[oh][ow] < (V-dist[0][0]) * 2) ok = 1; } cout << (ok ? "YES" : "NO") << endl; return 0; }