結果

問題 No.561 東京と京都
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-03-19 16:07:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 884 bytes
コンパイル時間 711 ms
コンパイル使用メモリ 76,084 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-11 23:30:11
合計ジャッジ時間 1,751 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,356 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 1 ms
4,352 KB
testcase_20 AC 2 ms
4,348 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;
    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