#include using namespace std; struct p{ double x,y; }; p psub(p a,p b){ return {a.x-b.x,a.y-b.y};} double dst(p a, p b, p c, p d){ a = psub(a,b); c = psub(c,d); double ret = a.x*c.y - a.y*c.x; return ret; } pair crossP(p a, p b, p c, p d){ double D = dst(b,a,d,c), s = dst(c,a,d,c), t = dst(b,a,a,c); s /= D; t /= D; if(D == 0.0) return {-1e9,-1e9}; if(s < 0.0 || 1.0 < s || t < 0.0 || 1.0 < t){return {-1e9,-1e9};} return {a.x + s*(b.x-a.x), a.y + s*(b.y-a.y)}; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int H,W; cin >> H >> W; vector> A(H,vector(W)); for(auto &h : A) for(auto &w : h) cin >> w; if(H == 1 && W == 1){cout << A.at(0).at(0) << endl; return 0;} vector> beam; for(int i=0; i= H || y < 0 || y >= W){ i2 = x-a; k2 = y-b; break; } } if(!one && grid == 1) continue; if(one && grid == 1) one = false; beam.push_back({i,k,i2,k2,a,b,p}); } } } int bs = beam.size(),answer = 0; for(int i=0; i= 0 && cx < H && cy >= 0 && cy < W) now -= A.at(cx).at(cy); } answer = max(answer,now); } } cout << answer << endl; }