package main import . "fmt" import . "os" import bf "bufio" func main() { rd := bf.NewReader(Stdin) var h, w int Fscan(rd, &h, &w) dp0 := make([]int, w) dp1 := make([]int, w) for i := 0; i < h; i++ { tmp0 := make([]int, w) tmp1 := make([]int, w) for j := 0; j < w; j++ { var a int Fscan(rd,&a) if i == 0 && j == 0 { tmp0[0] = a continue } if i > 0 { if dp0[j] > a { tmp0[j] = dp0[j] + a if dp1[j] > a { tmp1[j] = dp1[j] + a } } else if dp1[j] > a { tmp1[j] = max(dp0[j], dp1[j]+a) } else { tmp1[j] = dp0[j] } } if j > 0 { if tmp0[j-1] > a { tmp0[j] = max(tmp0[j], tmp0[j-1]+a) if tmp1[j-1] > a { tmp1[j] = max(tmp1[j], tmp1[j]+a) } } else if tmp1[j-1] > a { tmp1[j] = max(tmp1[j], tmp0[j-1], tmp1[j-1]+a) } else { tmp1[j] = max(tmp1[j], tmp0[j-1]) } } if i+1==h&&j+1==w { if tmp0[j] > a || tmp1[j] > a { Println("Yes") } else { Println("No") } } } dp0, dp1 = tmp0, tmp1 } }