結果

問題 No.561 東京と京都
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-03-19 16:30:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 899 bytes
コンパイル時間 958 ms
コンパイル使用メモリ 76,660 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-12 00:07:59
合計ジャッジ時間 1,950 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<climits>

typedef long long ll;

int main(int argc, char const *argv[]) {
    ll n, d;
    std::cin >> n >> d;
    std::vector<ll> t(n), k(n);
    for (int i = 0; i < n; i++) {
        std::cin >> t[i] >> k[i];
    }

    std::vector<std::vector<ll>> dp(2, std::vector<ll>(n + 1, LLONG_MIN));
    dp[0][0] = 0;
    dp[1][0] = -d;
    for (ll j = 0; j < n; j++) {
        for (ll i = 0; i < n; i++) {
            if (i == 0) {
                dp[0][j + 1] = std::max(dp[0][j + 1], dp[0][j] + t[j]);
                dp[1][j + 1] = std::max(dp[1][j + 1], dp[0][j] + k[j] - d);
            } else {
                dp[0][j + 1] = std::max(dp[0][j + 1], dp[1][j] + t[j] - d);
                dp[1][j + 1] = std::max(dp[1][j + 1], dp[1][j] + k[j]);
            }
        }
    }

    ll ans = std::max(dp[0][n], dp[1][n]);
    std::cout << ans << std::endl;
}
0