結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 103 ms
53,012 KB
testcase_01 AC 101 ms
52,588 KB
testcase_02 AC 98 ms
52,612 KB
testcase_03 AC 110 ms
53,892 KB
testcase_04 AC 109 ms
53,884 KB
testcase_05 AC 111 ms
54,020 KB
testcase_06 AC 111 ms
54,156 KB
testcase_07 AC 120 ms
53,756 KB
testcase_08 AC 109 ms
52,792 KB
testcase_09 AC 111 ms
53,452 KB
testcase_10 AC 105 ms
53,064 KB
testcase_11 AC 122 ms
54,036 KB
testcase_12 AC 130 ms
54,444 KB
testcase_13 AC 124 ms
54,428 KB
testcase_14 AC 127 ms
54,740 KB
testcase_15 AC 131 ms
54,400 KB
testcase_16 AC 129 ms
54,060 KB
testcase_17 AC 128 ms
54,368 KB
testcase_18 AC 139 ms
54,268 KB
testcase_19 AC 127 ms
54,376 KB
testcase_20 AC 128 ms
54,192 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] + t - d);
      long kyoto = Math.max(dp[i - 1][0] + k - 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