結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
41,676 KB
testcase_01 AC 121 ms
40,800 KB
testcase_02 AC 121 ms
41,148 KB
testcase_03 WA -
testcase_04 AC 116 ms
41,468 KB
testcase_05 AC 107 ms
41,528 KB
testcase_06 AC 118 ms
41,536 KB
testcase_07 AC 112 ms
41,316 KB
testcase_08 AC 115 ms
41,364 KB
testcase_09 AC 105 ms
41,624 KB
testcase_10 AC 118 ms
41,328 KB
testcase_11 AC 127 ms
41,540 KB
testcase_12 AC 147 ms
41,456 KB
testcase_13 AC 130 ms
41,540 KB
testcase_14 AC 131 ms
41,836 KB
testcase_15 AC 130 ms
41,328 KB
testcase_16 AC 133 ms
41,704 KB
testcase_17 AC 136 ms
41,204 KB
testcase_18 WA -
testcase_19 AC 128 ms
41,504 KB
testcase_20 AC 145 ms
41,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    int[][] dp = new int[n][2];
    int t0 = sc.nextInt();
    int k0 = sc.nextInt();
    dp[0][0] = t0;
    dp[0][1] = k0 - d;
    for(int i = 1; i < n; i++) {
      int t = sc.nextInt();
      int k = sc.nextInt();
      int tokyo = Math.max(dp[i - 1][0] + t, dp[i - 1][1] + k - d);
      int 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