結果

問題 No.561 東京と京都
ユーザー TamuoTamuoTamuoTamuoTamuoTamuo
提出日時 2019-07-05 15:55:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,127 bytes
コンパイル時間 1,703 ms
コンパイル使用メモリ 171,636 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 18:57:30
合計ジャッジ時間 2,834 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define SPACEREP(lst,itr) for(auto itr=lst.begin(); itr!=lst.end();++itr){cout<<*itr<<(++itr!=anslist.end()?" ":"\n");itr--;}
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

ll dp[101][2];

int main(){
    ll n,d,tmp;
    cin >> n >> d;
    vector<vector<ll>> input(n+1,vector<ll>(2));
    REP(i,1,n+1){
        REP(j,0,2){
            cin >> tmp;
            input[i][j]=tmp;
        }
    }

    dp[1][0]=input[1][0];
    dp[1][1]=input[1][1]-d;

    REP(i,1,n){
        dp[i+1][0] = max(dp[i][0]+input[i+1][0],dp[i][1]+input[i+1][0]-d);
        dp[i+1][1] = max(dp[i][0]+input[i+1][1]-d,dp[i][1]+input[i+1][1]);
    }
    cout << max(dp[n][0],dp[n][1]) <<endl;

}
0