結果

問題 No.561 東京と京都
ユーザー aaaaasatoriaaaaasatori
提出日時 2018-02-27 04:29:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 615 bytes
コンパイル時間 5,009 ms
コンパイル使用メモリ 74,652 KB
実行使用メモリ 55,924 KB
最終ジャッジ日時 2023-08-17 11:51:22
合計ジャッジ時間 7,795 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,924 KB
testcase_01 AC 122 ms
53,864 KB
testcase_02 AC 123 ms
55,424 KB
testcase_03 AC 123 ms
55,424 KB
testcase_04 AC 122 ms
55,840 KB
testcase_05 AC 123 ms
55,744 KB
testcase_06 AC 121 ms
55,844 KB
testcase_07 AC 123 ms
55,720 KB
testcase_08 AC 123 ms
55,892 KB
testcase_09 AC 125 ms
55,856 KB
testcase_10 AC 129 ms
53,648 KB
testcase_11 AC 133 ms
55,764 KB
testcase_12 AC 146 ms
55,640 KB
testcase_13 AC 146 ms
55,720 KB
testcase_14 AC 144 ms
55,480 KB
testcase_15 AC 146 ms
55,520 KB
testcase_16 AC 144 ms
55,700 KB
testcase_17 AC 141 ms
55,688 KB
testcase_18 AC 141 ms
55,840 KB
testcase_19 AC 140 ms
55,760 KB
testcase_20 AC 141 ms
55,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No561 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int t[] = new int[N];
		int k[] = new int[N];
		for(int i = 0;i < N;i++) {
			t[i] = sc.nextInt();
			k[i] = sc.nextInt();
		}
		int tmax[] = new int[N];
		int kmax[] = new int[N];
		tmax[0] = t[0];
		kmax[0] = k[0] - D;
		for(int i = 1;i < N;i++) {
			tmax[i] = Math.max(tmax[i-1] + t[i],kmax[i-1] + t[i] - D);
			kmax[i] = Math.max(kmax[i-1] + k[i],tmax[i-1] + k[i] - D);
		}
		System.out.println(Math.max(tmax[N-1], kmax[N-1]));
	}
}
0