結果
| 問題 | 
                            No.1199 お菓子配り-2
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-08-28 21:41:28 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 130 ms / 1,000 ms | 
| コード長 | 773 bytes | 
| コンパイル時間 | 1,214 ms | 
| コンパイル使用メモリ | 96,820 KB | 
| 最終ジャッジ日時 | 2025-01-13 16:52:22 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 45 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <map>
using namespace std;
typedef long long int ll;
ll dp[1010][2];
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            ll x; cin >> x;
            a[i]+=x;
        }
    }
    for(int i=0;i<1010;i++){
        for(int j=0;j<2;j++){
            dp[i][j]=-1e18;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<2;j++){
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
            dp[i+1][j^1]=max(dp[i+1][j^1],dp[i][j]+(j%2==0?1LL:-1LL)*a[i]);
        }
    }
    cout << max(dp[n][0],dp[n][1]) << endl;
}