結果

問題 No.561 東京と京都
ユーザー Tsukasa_Type
提出日時 2018-02-24 02:25:00
言語 Java
(openjdk 23)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 568 bytes
コンパイル時間 4,286 ms
コンパイル使用メモリ 73,640 KB
実行使用メモリ 41,568 KB
最終ジャッジ日時 2024-10-11 00:00:56
合計ジャッジ時間 6,123 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

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