/* -*- coding: utf-8 -*- * * 2509.cc: No.2509 Beam Shateki - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_H = 100; const int MAX_W = 100; /* typedef */ /* global variables */ int as[MAX_H][MAX_W]; int hs[MAX_H], vs[MAX_W], ps[MAX_H + MAX_W], qs[MAX_H + MAX_W]; /* subroutines */ /* main */ int main() { int h, w; scanf("%d%d", &h, &w); for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) { scanf("%d", as[i] + j); hs[i] += as[i][j]; vs[j] += as[i][j]; ps[i + j] += as[i][j]; qs[i + (w - 1 - j)] += as[i][j]; } int maxs = 0; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) { int ds[4] = { hs[i], vs[j], ps[i + j], qs[i + (w - 1 - j)] }; sort(ds, ds + 4); int s = ds[3] + ds[2] - as[i][j]; maxs = max(maxs ,s ); } for (int i = 0; i < h; i++) for (int j = i + 1; j < h; j++) maxs = max(maxs, hs[i] + hs[j]); for (int i = 0; i < w; i++) for (int j = i + 1; j < w; j++) maxs = max(maxs, vs[i] + vs[j]); int hw = h + w - 1; for (int i = 0; i < hw; i++) for (int j = i + 1; j < hw; j++) maxs = max(maxs, max(ps[i] + ps[j], qs[i] + qs[j])); printf("%d\n", maxs); return 0; }