結果

問題 No.1104 オンライン点呼
ユーザー ks2m
提出日時 2020-07-03 22:04:01
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 936 bytes
コンパイル時間 2,425 ms
コンパイル使用メモリ 78,048 KB
実行使用メモリ 64,048 KB
最終ジャッジ日時 2024-09-17 01:57:31
合計ジャッジ時間 9,016 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int k = Integer.parseInt(sa[1]);

		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}

		sa = br.readLine().split(" ");
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			b[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		long[] dp = new long[n];
		for (int i = 1; i < n; i++) {
			dp[i] = dp[i - 1] + a[i - 1] + b[i];
			if (i > 1) {
				long val = dp[i - 2] + a[i - 2] + b[i] + k;
				dp[i] = Math.min(dp[i], val);
			}
		}

		long ans = 0;
		for (int i = 0; i < dp.length; i++) {
			ans = Math.max(ans, dp[i]);
		}
		System.out.println(ans);
	}
}
0