using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; //using static CompLib.CompLib; //using DataStructure; namespace atcoder { class Program { const int intMax = 1000000000; const long longMax = 2000000000000000000; static void Main(string[] args) { var HWYX = Console.ReadLine().Trim().Split().Select(int.Parse).ToArray(); int H = HWYX[0]; int W = HWYX[1]; int Y = HWYX[2] - 1; int X = HWYX[3] - 1; var A = new long[H, W]; for (int i = 0; i < H; i++) { var read = Console.ReadLine().Trim().Split().Select(int.Parse).ToArray(); for (int j = 0; j < W; j++) { A[i, j] = read[j]; } } var pq = new PriorityQueue(25000000, Comparer.Create((x, y) => y.CompareTo(x))); pq.Push(new Point(Y, X, A[Y, X])); var move = new (int, int)[4] { (1, 0), (-1, 0), (0, 1), (0, -1) }; var visited = new bool[H, W]; long attack = A[Y, X]; while (pq.Count > 0) { Point now = pq.Pop(); if (now.y != Y || now.x != X) { if (attack <= now.cost) { Console.WriteLine("No"); return; } else { attack += now.cost; } } foreach (var i in move) { int ny = now.y + i.Item1; int nx = now.x + i.Item2; if (ny >= 0 && ny < H && nx >= 0 && nx < W && !visited[ny, nx]) { visited[ny, nx] = true; pq.Push(new Point(ny, nx, A[ny, nx])); } } } Console.WriteLine("Yes"); } } public struct Point : IComparable { public int y; public int x; public long cost; public Point(int y, int x, long cost) { this.y = y; this.x = x; this.cost = cost; } public int CompareTo(Point other) => cost.CompareTo(other.cost); } public class PriorityQueue where T : IComparable { private readonly T[] _array; private readonly IComparer _comparer; public int Count {get; private set;} = 0; public T Root => _array[0]; public PriorityQueue(int capacity, IComparer comparer = null) { _array = new T[capacity]; _comparer = comparer; } //要素追加 public void Push(T item) { _array[this.Count] = item; Count += 1; var n = Count - 1; while(n != 0) { var parent = (n - 1) / 2; if(Compare(_array[n], _array[parent]) > 0) { Swap(n, parent); n = parent; } else { break; } } } //優先度の一番高いものの取り出し public T Pop() { Swap(0, this.Count - 1); Count -= 1; var parent = 0; while(true) { var chiled = 2 * parent + 1; if(chiled > Count - 1) break; if(chiled < Count - 1 && Compare(_array[chiled], _array[chiled + 1]) < 0) chiled += 1; if(Compare(_array[parent], _array[chiled]) < 0) { Swap(parent, chiled); parent = chiled; } else { break; } } return _array[Count]; } //すべての値を取り出し //引数1:True Pop(), False 値を取り出だけ public IEnumerable GetAllElements(bool withPop = true) { int count = Count; for(int i = 0; i < count; i++) { if(withPop) yield return Pop(); else yield return _array[count - i - 1]; } } // 引数同士を比較 private int Compare(T a, T b) { if(_comparer == null) return a.CompareTo(b); return _comparer.Compare(a, b); } //引数2箇所の入れ替え private void Swap(int a, int b) { var temp = _array[a]; _array[a] = _array[b]; _array[b] = temp; } } }