#include #define rep(i,a,b) for(int i=int(a);i P; typedef pair PP; int dy[] = {1, 0, -1, 0}; int dx[] = {0, 1, 0, -1}; int cost[210][210];//cost[i][j] i->jのコスト int dist[210][210];//距離 int N,V,X,Y; void dijkstra(int y, int x){ rep(i, 0, N)rep(j, 0, N)dist[i][j] = INF; // priority_queue, greater > que; que.push(make_pair(0, make_pair(y, x))); dist[y][x] = 0; while(!que.empty()){ auto c = que.top().first; auto now = que.top().second; que.pop(); // if(dist[now.first][now.second] < c) continue; rep(i, 0, 4){ int ny = now.first + dy[i], nx = now.second + dx[i]; if(!(0 <= ny && ny < N && 0 <= nx && nx < N)) continue; if(dist[ny][nx] <= c + cost[ny][nx]) continue; dist[ny][nx] = c + cost[ny][nx]; que.push(make_pair(dist[ny][nx], make_pair(ny, nx))); } } } main(){ cin >> N >> V >> X >> Y; rep(i,0,N)rep(j,0,N)cin >> cost[i][j]; string ans[] = {"NO", "YES"}; dijkstra(0, 0); if(dist[N-1][N-1] < V){ cout << "YES" << endl; return 0; } if(X != 0 || Y != 0 && dist[Y-1][X-1] < V){ int ocost = dist[Y-1][X-1]; dijkstra(Y-1, X-1); if(2 * (V - ocost) > dist[N-1][N-1]){ cout << "YES" << endl; return 0; } } cout << "NO" << endl; }