結果

問題 No.561 東京と京都
ユーザー OlderInvestorOlderInvestor
提出日時 2017-09-20 21:12:47
言語 Java
(openjdk 23)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 808 bytes
コンパイル時間 6,404 ms
コンパイル使用メモリ 74,156 KB
実行使用メモリ 41,628 KB
最終ジャッジ日時 2024-11-08 09:16:30
合計ジャッジ時間 8,404 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Scanner;
import static java.lang.Math.max;

public class No561 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(), d = sc.nextInt();
        int t, k, beforeT, beforeK;
        int resultT = 0, resultK = 0;
        boolean tokyo = true;

        beforeT = sc.nextInt();
        beforeK = sc.nextInt() - d;
        resultT = beforeT;
        resultK = beforeK;

        for(int i = 0; i < n - 1; i++) {
            t = sc.nextInt();
            k = sc.nextInt();
            resultT = t + max(beforeT, beforeK - d);
            resultK = k + max(beforeK, beforeT - d);
            beforeT = resultT;
            beforeK = resultK;
        }

        System.out.println(max(resultT, resultK));
    }
}
0