結果

問題 No.561 東京と京都
ユーザー YamaKasaYamaKasa
提出日時 2018-09-24 21:24:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 654 bytes
コンパイル時間 3,476 ms
コンパイル使用メモリ 76,928 KB
実行使用メモリ 57,612 KB
最終ジャッジ日時 2023-10-24 14:41:52
合計ジャッジ時間 7,482 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
57,440 KB
testcase_01 AC 127 ms
55,768 KB
testcase_02 AC 127 ms
57,396 KB
testcase_03 AC 122 ms
57,152 KB
testcase_04 AC 121 ms
57,436 KB
testcase_05 AC 118 ms
57,308 KB
testcase_06 AC 118 ms
57,280 KB
testcase_07 AC 119 ms
57,348 KB
testcase_08 AC 114 ms
56,668 KB
testcase_09 AC 123 ms
57,596 KB
testcase_10 AC 122 ms
57,572 KB
testcase_11 AC 131 ms
55,584 KB
testcase_12 AC 126 ms
55,056 KB
testcase_13 AC 136 ms
57,572 KB
testcase_14 AC 130 ms
57,480 KB
testcase_15 AC 133 ms
57,596 KB
testcase_16 AC 133 ms
57,604 KB
testcase_17 AC 132 ms
57,612 KB
testcase_18 AC 134 ms
57,580 KB
testcase_19 AC 134 ms
57,388 KB
testcase_20 AC 142 ms
57,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int D = scan.nextInt();
		int[]T = new int[N];
		int[]K = new int[N];
		for(int i = 0; i < N; i++) {
			T[i] = scan.nextInt();
			K[i] = scan.nextInt();
		}
		scan.close();
		int[][]dp = new int[N + 1][2];
		dp[1][0] = T[0];
		dp[1][1] = K[0] - D;
		for(int i = 2; i <= N; i++) {
			dp[i][0] = Math.max(dp[i - 1][0] + T[i - 1], dp[i - 1][1] - D + T[i - 1]);
			dp[i][1] = Math.max(dp[i - 1][0] - D + K[i - 1], dp[i - 1][1] + K[i - 1]);
		}
		System.out.println(Math.max(dp[N][0], dp[N][1]));
	}
}
0