void main() { runSolver(); } void problem() { auto H = scan!int; auto W = scan!int; auto A = scan!long(H * W).chunks(W).array; auto solve() { auto dp = new long[][][](H, W, 2); dp[0][0][] = A[0][0]; alias Point = Tuple!(int, "x", int, "y", int, "c"); auto visited = new bool[][][](H, W, 2); for(auto q = DList!Point([Point(0, 0, 0)]); !q.empty;) { auto p = q.front; q.removeFront; if (visited[p.y][p.x][p.c]) continue; visited[p.y][p.x][p.c] = true; auto strength = dp[p.y][p.x][p.c]; foreach(a; [Point(p.x + 1, p.y, p.c), Point(p.x, p.y + 1, p.c)]) { if (a.x >= W || a.y >= H) continue; // deb(a, strength); if (strength > A[a.y][a.x]) { if (dp[a.y][a.x][a.c].chmax(strength + A[a.y][a.x])) { q.insertBack(Point(a.x, a.y, a.c)); } } else { if (a == Point(W - 1, H - 1, 0)) continue; if (a.c == 0 && dp[a.y][a.x][1].chmax(strength)) { q.insertBack(Point(a.x, a.y, 1)); } } } } // dp.deb; return YESNO[dp[$ - 1][$ - 1].maxElement > 0]; } outputForAtCoder(&solve); } // ---------------------------------------------- import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop; T[][] combinations(T)(T[] s, in long m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); } string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } T scan(T)(){ return scan.to!T; } T[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; } void deb(T ...)(T t){ debug writeln(t); } long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; } bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; } bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; } string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; } ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}} string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; } struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x>>".writefln(benchmark!problem(1)); BORDER.writeln; } } else problem(); } enum YESNO = [true: "Yes", false: "No"]; // -----------------------------------------------