結果

問題 No.561 東京と京都
ユーザー seaesaeseaesae
提出日時 2018-11-24 22:31:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 576 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 52,152 KB
実行使用メモリ 7,692 KB
最終ジャッジ日時 2023-08-26 05:02:14
合計ジャッジ時間 1,475 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,692 KB
testcase_01 AC 3 ms
7,448 KB
testcase_02 AC 2 ms
7,444 KB
testcase_03 AC 2 ms
7,632 KB
testcase_04 AC 2 ms
7,496 KB
testcase_05 AC 2 ms
7,576 KB
testcase_06 AC 3 ms
7,372 KB
testcase_07 AC 2 ms
7,392 KB
testcase_08 AC 2 ms
7,548 KB
testcase_09 AC 3 ms
7,392 KB
testcase_10 AC 2 ms
7,448 KB
testcase_11 AC 2 ms
7,444 KB
testcase_12 AC 2 ms
7,444 KB
testcase_13 AC 2 ms
7,372 KB
testcase_14 AC 2 ms
7,448 KB
testcase_15 AC 3 ms
7,468 KB
testcase_16 AC 3 ms
7,452 KB
testcase_17 AC 3 ms
7,440 KB
testcase_18 AC 2 ms
7,392 KB
testcase_19 AC 3 ms
7,468 KB
testcase_20 AC 2 ms
7,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

const int INF=-100000000;
int N,D;
int T[10000100],K[10000100];
//dp[i][j]:i日目にj=0→東京、j=1→京都にいるときの増やせる金額のmax
int dp[1000010][2];

int main(){
    
    cin>>N>>D;
    for(int i=0; i<N; i++)cin>>T[i]>>K[i];
    
    //dp初期条件:dp[0][0]=0,dp[0][1]=INF;
    dp[0][0]=0,dp[0][1]=INF;
    for(int i=0; i<N; i++){
        dp[i+1][0]=max(dp[i][0]+T[i],dp[i][1]-D+T[i]);
        dp[i+1][1]=max(dp[i][1]+K[i],dp[i][0]-D+K[i]);
    }
    cout<<max(dp[N][0],dp[N][1])<<endl;
    
    return 0;
}
0