結果

問題 No.561 東京と京都
ユーザー hiromi-mihiromi-mi
提出日時 2018-12-31 00:00:42
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 747 bytes
コンパイル時間 522 ms
コンパイル使用メモリ 64,180 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 16:43:01
合計ジャッジ時間 1,105 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <cmath>
/*
#include <map>
#include <functional>
#include <set>
#include <queue>
#include <cstdio>
*/
using namespace std;
typedef long long ll;
//typedef pair<ll, ll> P;

#define rep(i, m) for(ll i=0;i<m;i++)

int N, D;
int T[110][2];
ll dp[110][2];
ll ep[110][110];
// rec(i, j) = max(rec(i, ))

int main() {
   cin >> N >> D;
   rep(i, N) {
      cin >> T[i][0] >> T[i][1];
   }
   dp[0][0] = 0;
   dp[0][1] = -D;
   rep(i,N) {
      rep(j, 2) {
         dp[i+1][j] = max(dp[i+1][j], dp[i][j] + T[i][j]);
         dp[i+1][(1-j)] = max(dp[i+1][1-j], dp[i][j] + T[i][1-j]-D);
      }
   }
   cout << max({dp[N-1][0], ep[N-1][0] }) << endl;
}
0