結果

問題 No.561 東京と京都
ユーザー tomorrowtomorrow
提出日時 2022-05-18 03:23:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 775 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 201,364 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 07:28:32
合計ジャッジ時間 2,907 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T& a, const T& b)
{
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
constexpr ll inf = (1LL << 62);
long dp[110][2];
int main()
{
    ll n, d;
    cin >> n >> d;
    vector<ll> t(n), k(n);
    for (ll i = 0; i < n; ++i) {
        cin >> t[i] >> k[i];
    }
    dp[0][0] = 0;
    dp[0][1] = -d;
    for (ll i = 0; i < n; ++i) {
        dp[i + 1][0] = max(dp[i][1] - d + t[i], dp[i][0] + t[i]);
        dp[i + 1][1] = max(dp[i][0] - d + k[i], dp[i][1] + k[i]);
    }
    cout << max(dp[n][0], dp[n][1]) << endl;
}
0