結果

問題 No.561 東京と京都
ユーザー tetsutetsu
提出日時 2017-08-26 01:13:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 769 bytes
コンパイル時間 3,788 ms
コンパイル使用メモリ 77,692 KB
実行使用メモリ 52,208 KB
最終ジャッジ日時 2024-04-23 16:31:27
合計ジャッジ時間 6,345 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
52,208 KB
testcase_01 AC 111 ms
40,916 KB
testcase_02 AC 112 ms
40,996 KB
testcase_03 AC 103 ms
40,328 KB
testcase_04 AC 114 ms
41,348 KB
testcase_05 AC 107 ms
40,400 KB
testcase_06 AC 111 ms
41,452 KB
testcase_07 AC 101 ms
40,040 KB
testcase_08 AC 111 ms
40,988 KB
testcase_09 AC 116 ms
41,236 KB
testcase_10 AC 118 ms
41,476 KB
testcase_11 AC 124 ms
41,124 KB
testcase_12 AC 127 ms
41,644 KB
testcase_13 AC 129 ms
41,424 KB
testcase_14 AC 137 ms
41,968 KB
testcase_15 AC 130 ms
41,420 KB
testcase_16 AC 128 ms
41,692 KB
testcase_17 AC 124 ms
41,264 KB
testcase_18 AC 134 ms
41,724 KB
testcase_19 AC 134 ms
41,676 KB
testcase_20 AC 124 ms
41,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yuki172;

import java.util.Scanner;

public class D {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long D = sc.nextLong();
		long[] T = new long[N];
		long[] K = new long[N];
		long[] Tans = new long[N];
		long[] Kans = new long[N];
 		for(int i=0; i<N; i++) {
			T[i] = sc.nextLong();
			K[i] = sc.nextLong();
		}
 		sc.close();
		Tans[0] = T[0];
		Kans[0] = K[0] - D;
 		for(int i=1; i<N; i++) {
 			Tans[i] = T[i] + max(Tans[i-1], Kans[i-1]-D);
 			Kans[i] = K[i] + max(Tans[i-1]-D, Kans[i-1]);
 		}
		System.out.println(max(Tans[N-1], Kans[N-1]));
	}
	
	private static long max(long a, long b) {
		if(a > b) {
			return a;
		} else {
			return b;
		}
	}

}
0