import sys import heapq from collections import deque def main(): H, W, Y, X = map(int, sys.stdin.readline().split()) Y -= 1 X -= 1 grid = [] for _ in range(H): row = list(map(int, sys.stdin.readline().split())) grid.append(row) processed = [[False for _ in range(W)] for _ in range(H)] in_queue = [[False for _ in range(W)] for _ in range(H)] bfs_queue = deque() bfs_queue.append((Y, X)) processed[Y][X] = True heap = [] S = grid[Y][X] # Initial BFS to find all reachable enemies with attack <= S while bfs_queue: i, j = bfs_queue.popleft() for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]: ni = i + di nj = j + dj if 0 <= ni < H and 0 <= nj < W: if not processed[ni][nj]: if (ni, nj) != (Y, X) and grid[ni][nj] <= S: if not in_queue[ni][nj]: heapq.heappush(heap, (grid[ni][nj], ni, nj)) in_queue[ni][nj] = True while heap: ai, i, j = heapq.heappop(heap) if ai > S: print("No") return if processed[i][j]: continue processed[i][j] = True S += ai # Add this cell to BFS queue to explore further bfs_queue.append((i, j)) # Explore neighbors to find new reachable cells while bfs_queue: ci, cj = bfs_queue.popleft() for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]: ni = ci + di nj = cj + dj if 0 <= ni < H and 0 <= nj < W: if not processed[ni][nj]: if (ni, nj) != (Y, X) and grid[ni][nj] <= S: if not in_queue[ni][nj]: heapq.heappush(heap, (grid[ni][nj], ni, nj)) in_queue[ni][nj] = True # Check if all enemies are processed total_enemies = 0 processed_enemies = 0 for i in range(H): for j in range(W): if (i, j) != (Y, X): total_enemies += 1 if processed[i][j]: processed_enemies += 1 if processed_enemies == total_enemies: print("Yes") else: print("No") if __name__ == "__main__": main()