結果

問題 No.561 東京と京都
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-24 02:25:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 568 bytes
コンパイル時間 5,091 ms
コンパイル使用メモリ 74,424 KB
実行使用メモリ 41,696 KB
最終ジャッジ日時 2024-04-19 07:21:04
合計ジャッジ時間 5,669 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
40,108 KB
testcase_01 AC 114 ms
40,876 KB
testcase_02 AC 107 ms
41,060 KB
testcase_03 AC 119 ms
41,144 KB
testcase_04 AC 125 ms
41,604 KB
testcase_05 AC 129 ms
41,036 KB
testcase_06 AC 133 ms
40,952 KB
testcase_07 AC 129 ms
41,124 KB
testcase_08 AC 117 ms
40,076 KB
testcase_09 AC 126 ms
41,272 KB
testcase_10 AC 141 ms
41,240 KB
testcase_11 AC 144 ms
41,344 KB
testcase_12 AC 151 ms
41,696 KB
testcase_13 AC 154 ms
41,356 KB
testcase_14 AC 143 ms
41,160 KB
testcase_15 AC 151 ms
41,524 KB
testcase_16 AC 148 ms
41,572 KB
testcase_17 AC 145 ms
41,548 KB
testcase_18 AC 158 ms
41,432 KB
testcase_19 AC 162 ms
41,468 KB
testcase_20 AC 152 ms
41,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int fare = sc.nextInt();
		long[] dpt = new long[n];
		long[] dpk = new long[n];
		dpt[0] = sc.nextInt();
		dpk[0] = sc.nextInt()-fare;
		int tokyo = 0;
		int kyoto = 0;
		for (int i=1; i<n; i++) {
			tokyo = sc.nextInt();
			kyoto = sc.nextInt();
			dpt[i] = tokyo + Math.max(dpt[i-1],dpk[i-1]-fare);
			dpk[i] = kyoto + Math.max(dpt[i-1]-fare,dpk[i-1]);
		}
		System.out.println(Math.max(dpt[n-1],dpk[n-1]));
	}
}
0