#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; static const double EPS = 1e-8; static const double PI = 4.0 * atan(1.0); static const double PI2 = 8.0 * atan(1.0); #define REP(i,n) for(int i=0;i<(int)n;++i) #define ALL(c) (c).begin(),(c).end() #define CLEAR(v) memset(v,0,sizeof(v)) #define MP(a,b) make_pair((a),(b)) #define ABS(a) ((a)>0?(a):-(a)) #define FOR(i,s,n) for(int i=s;i<(int)n;++i) #define INF (1000000) int N, V, Ox, Oy; int L[202][202]; int c[202][202], d[202][202]; typedef pair> P; int ar[4][2] = { { 1, 0 }, { 0, -1 }, { -1, 0 }, { 0, 1 } }; void wf(int a[202][202], int sx, int sy) { priority_queue, greater

> q; q.push(MP(0, MP(sx, sy))); while (!q.empty()) { P t = q.top(); q.pop(); int v = t.first, x = t.second.first, y = t.second.second; REP(i, 4) { int ax = x + ar[i][0], ay = y + ar[i][1]; if (a[ax][ay] > v + L[ax][ay]) { a[ax][ay] = v + L[ax][ay]; q.push(MP(a[ax][ay], MP(ax, ay))); } } } } int main(int argc, char **argv) { cin >> N >> V >> Ox >> Oy; FOR(y, 1, N + 1) FOR(x, 1, N + 1) { cin >> L[x][y]; c[x][y] = d[x][y] = INF; } REP(i, N + 2) { L[i][0] = L[i][N + 1] = L[0][i] = L[N + 1][i] = INF; c[i][0] = c[i][N + 1] = c[0][i] = c[N + 1][i] = -1; d[i][0] = d[i][N + 1] = d[0][i] = d[N + 1][i] = -1; } wf(c, 1, 1); bool res = c[N][N] < V; if (!res && c[Ox][Oy] < V) { wf(d, Ox, Oy); res = d[N][N] < (V - c[Ox][Oy]) * 2; } cout << (res ? "YES" : "NO") << endl; return 0; }