結果
問題 | No.561 東京と京都 |
ユーザー |
|
提出日時 | 2024-06-10 18:37:52 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 844 bytes |
コンパイル時間 | 3,425 ms |
コンパイル使用メモリ | 76,836 KB |
実行使用メモリ | 54,528 KB |
最終ジャッジ日時 | 2025-01-02 14:07:08 |
合計ジャッジ時間 | 6,847 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 14 WA * 3 |
ソースコード
import java.util.*;import java.lang.*;import java.io.*;// The main method must be in a class named "Main".class Main {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();}long t1 = t[0];long k1 = k[0]-d;long tt = 0l;long kk = 0l;for (int i=1; i<n; i++) {tt = Math.max(t1 + t[i], k1 - d + t[i]);kk = Math.max(k1 + k[i], t1 - d + k[i]);t1 = tt;k1 = kk;}System.out.println(Math.max(tt,kk));}}