結果

問題 No.561 東京と京都
ユーザー htensaihtensai
提出日時 2019-11-14 21:33:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 518 bytes
コンパイル時間 4,131 ms
コンパイル使用メモリ 74,796 KB
実行使用メモリ 57,876 KB
最終ジャッジ日時 2023-10-22 00:47:03
合計ジャッジ時間 7,741 ms
ジャッジサーバーID
(参考情報)
judge9 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
56,324 KB
testcase_01 AC 118 ms
57,616 KB
testcase_02 AC 103 ms
56,232 KB
testcase_03 AC 115 ms
57,328 KB
testcase_04 AC 112 ms
57,364 KB
testcase_05 AC 109 ms
57,232 KB
testcase_06 AC 103 ms
56,312 KB
testcase_07 AC 113 ms
57,400 KB
testcase_08 AC 101 ms
54,164 KB
testcase_09 AC 119 ms
57,376 KB
testcase_10 AC 146 ms
57,780 KB
testcase_11 AC 118 ms
57,768 KB
testcase_12 AC 122 ms
57,616 KB
testcase_13 AC 130 ms
57,872 KB
testcase_14 AC 142 ms
57,680 KB
testcase_15 AC 128 ms
57,556 KB
testcase_16 AC 128 ms
57,576 KB
testcase_17 AC 127 ms
57,588 KB
testcase_18 AC 143 ms
57,620 KB
testcase_19 AC 129 ms
57,580 KB
testcase_20 AC 136 ms
57,876 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[2][n + 1];
		dp[1][0] = Integer.MIN_VALUE / 10;
		for (int i = 1; i <= n; i++) {
		    int a = sc.nextInt();
		    int b = sc.nextInt();
		    dp[0][i] = Math.max(dp[0][i - 1], dp[1][i - 1] - d) + a;
		    dp[1][i] = Math.max(dp[0][i - 1] - d, dp[1][i - 1]) + b;
		}
		System.out.println(Math.max(dp[0][n], dp[1][n]));
	}
}
0