結果

問題 No.561 東京と京都
ユーザー uw_yu1rabbituw_yu1rabbit
提出日時 2020-09-02 14:15:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,403 bytes
コンパイル時間 1,161 ms
コンパイル使用メモリ 86,112 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-01 10:31:32
合計ジャッジ時間 2,068 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
#define rep(i, n) for (i32 i = 0; i < (i32)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 n,d;
cin >> n >> d;
vector<i64> t(n),k(n);
rep(i,n)cin >> t[i] >> k[i];
vector<vector<i64>> dp(n + 1,vector<i64>(2,-1));
dp[0][0] = 0;
dp[0][1] = 0;
rep(i,n){
    rep(j,2){
        rep(l,2){
           if(j == l){
               if(l == 0){
                   dp[i + 1][l] = max(dp[i][l] + t[i],dp[i + 1][l]);
               }else{
                   if(i == 0){
                        dp[i + 1][l] = max(dp[i][l] + k[i] - d,dp[i + 1][l]);
                   }else{
                       dp[i + 1][l] = max(dp[i][l] + k[i],dp[i + 1][l]);
                   }
               }
           }else{
               if(l == 0){
                   dp[i + 1][l] = max(dp[i][j] + t[i] - d,dp[i + 1][l]);
               }else{
                   dp[i + 1][l] = max(dp[i][j] + k[i] - d,dp[i + 1][l]);
               }
           }
        }
    }
}
rep(i,n + 1){
    rep(j,2){
        cout << dp[i][j] << " \n"[j == 1];
    }
}
cout << max(dp[n][0],dp[n][1]) << endl;
}
0