#include #include using namespace std; using LL = long long; using P = pair; using Graph = vector>; const int INF = 1 << 29; const long long LINF = 1LL << 60; #define all(x) (x).begin(), (x).end() #define rep(i,n) for(int i = 0; i < (n); ++i) templatevoid chmin(T&a, T b){if(a > b) a = b;} templatevoid chmax(T&a, T b){if(a < b) a = b;} int main(){ int N, M; cin >> N >> M; vector A(N, 0); for(int i = 0; i < N; ++i){ for(int j = 0; j < M; ++j){ int tmp; cin >> tmp; A[i] += tmp; } } vector> dp(N+1, vector(2, 0)); for(int i = 0; i < N; ++i){ //you choose the i-th sweets //next even chmax(dp[i+1][0], dp[i][1] + A[i]); //next odd if(i!=0)chmax(dp[i+1][1], dp[i][0] - A[i]); //you dont choose the i-th sweets chmax(dp[i+1][0], dp[i][0]); chmax(dp[i+1][1], dp[i][1]); } cout << max(dp[N][0], dp[N][1]) << endl; }