結果

問題 No.561 東京と京都
ユーザー takeya_okinotakeya_okino
提出日時 2017-08-26 20:24:31
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 665 bytes
コンパイル時間 3,517 ms
コンパイル使用メモリ 77,500 KB
実行使用メモリ 54,512 KB
最終ジャッジ日時 2024-04-23 17:19:25
合計ジャッジ時間 5,943 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
41,368 KB
testcase_01 AC 135 ms
41,560 KB
testcase_02 AC 133 ms
41,308 KB
testcase_03 WA -
testcase_04 AC 133 ms
41,140 KB
testcase_05 AC 132 ms
41,508 KB
testcase_06 AC 116 ms
40,096 KB
testcase_07 AC 130 ms
41,412 KB
testcase_08 AC 132 ms
41,436 KB
testcase_09 AC 137 ms
41,076 KB
testcase_10 AC 141 ms
41,356 KB
testcase_11 AC 146 ms
41,688 KB
testcase_12 AC 147 ms
41,588 KB
testcase_13 AC 149 ms
41,544 KB
testcase_14 AC 147 ms
41,764 KB
testcase_15 AC 151 ms
42,004 KB
testcase_16 AC 152 ms
41,816 KB
testcase_17 AC 145 ms
41,480 KB
testcase_18 WA -
testcase_19 AC 149 ms
41,324 KB
testcase_20 AC 168 ms
41,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long d = sc.nextLong();
    long[][] dp = new long[n][2];
    long t0 = sc.nextLong();
    long k0 = sc.nextLong();
    dp[0][0] = t0;
    dp[0][1] = k0 - d;
    for(int i = 1; i < n; i++) {
      long t = sc.nextLong();
      long k = sc.nextLong();
      long tokyo = Math.max(dp[i - 1][0] + t, dp[i - 1][1] + k - d);
      long kyoto = Math.max(dp[i - 1][0] + t - d, dp[i - 1][1] + k);
      dp[i][0] = tokyo;
      dp[i][1] = kyoto;
    }
    System.out.println(Math.max(dp[n - 1][0], dp[n - 1][1]));
  }
}
0