#include #include #include #include template std::vector vec(int len, T elem) { return std::vector(len, elem); } template using MaxHeap = std::priority_queue; const std::vector> dxys{{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; void solve() { int n, m, ox, oy; std::cin >> n >> m >> ox >> oy; --ox, --oy; auto xss = vec(n, vec(n, 0)); for (auto& xs : xss) { for (auto& x : xs) std::cin >> x; } auto dp = vec(2, vec(n, vec(n, 0))); dp[0][0][0] = m; MaxHeap> heap; heap.emplace(dp[0][0][0], 0, 0, 0); while (!heap.empty()) { auto [d, t, x, y] = heap.top(); heap.pop(); if (d < dp[t][x][y]) continue; if (t == 0 && x == ox && y == oy) { dp[1][x][y] = dp[0][x][y] * 2; heap.emplace(dp[1][x][y], 1, x, y); } for (auto [dx, dy] : dxys) { int nx = x + dx, ny = y + dy; if (nx < 0 || n <= nx || ny < 0 || n <= ny || dp[t][nx][ny] >= dp[t][x][y] - xss[nx][ny]) continue; dp[t][nx][ny] = dp[t][x][y] - xss[nx][ny]; heap.emplace(dp[t][nx][ny], t, nx, ny); } } std::cout << (dp[0][n - 1][n - 1] == 0 && dp[1][n - 1][n - 1] == 0 ? "NO" : "YES") << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }