結果

問題 No.1375 Divide and Update
ユーザー ks2mks2m
提出日時 2021-02-05 22:17:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 523 ms / 2,000 ms
コード長 1,723 bytes
コンパイル時間 4,533 ms
コンパイル使用メモリ 74,376 KB
実行使用メモリ 78,420 KB
最終ジャッジ日時 2023-09-15 08:34:13
合計ジャッジ時間 12,747 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,460 KB
testcase_01 AC 43 ms
49,608 KB
testcase_02 AC 43 ms
49,340 KB
testcase_03 AC 43 ms
49,924 KB
testcase_04 AC 44 ms
49,248 KB
testcase_05 AC 45 ms
49,808 KB
testcase_06 AC 43 ms
49,536 KB
testcase_07 AC 43 ms
49,424 KB
testcase_08 AC 44 ms
49,596 KB
testcase_09 AC 43 ms
49,512 KB
testcase_10 AC 518 ms
74,328 KB
testcase_11 AC 520 ms
75,260 KB
testcase_12 AC 349 ms
63,504 KB
testcase_13 AC 334 ms
62,856 KB
testcase_14 AC 523 ms
71,528 KB
testcase_15 AC 504 ms
70,924 KB
testcase_16 AC 504 ms
72,592 KB
testcase_17 AC 501 ms
71,508 KB
testcase_18 AC 503 ms
72,132 KB
testcase_19 AC 503 ms
72,292 KB
testcase_20 AC 462 ms
78,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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 x = Integer.parseInt(sa[1]);
		int y = Integer.parseInt(sa[2]);
		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		int[] dx = new int[n];
		int[] dy = new int[n];
		for (int i = 0; i < n; i++) {
			dx[i] = x - a[i];
			dy[i] = y - a[i];
		}

		long[] dpx = new long[n];
		long[] dpx1 = new long[n];
		dpx[0] = dx[0];
		dpx1[0] = dx[0];
		for (int i = 1; i < n; i++) {
			if (dx[i] >= 0) {
				dpx[i] = Math.max(dpx1[i - 1] + dx[i], dx[i]);
			} else {
				dpx[i] = Math.max(dpx[i - 1], dx[i]);
			}
			dpx1[i] = Math.max(dpx1[i - 1] + dx[i], dx[i]);
		}

		long[] dpy = new long[n];
		long[] dpy1 = new long[n];
		dpy[n - 1] = dy[n - 1];
		dpy1[n - 1] = dy[n - 1];
		for (int i = n - 2; i >= 0; i--) {
			if (dy[i] >= 0) {
				dpy[i] = Math.max(dpy1[i + 1] + dy[i], dy[i]);
			} else {
				dpy[i] = Math.max(dpy[i + 1], dy[i]);
			}
			dpy1[i] = Math.max(dpy1[i + 1] + dy[i], dy[i]);
		}

		long total = 0;
		for (int i = 0; i < n; i++) {
			total += a[i];
		}
		for (int i = 1; i < n; i++) {
			dpx[i] = Math.max(dpx[i], dpx[i - 1]);
		}
		for (int i = n - 2; i >= 0; i--) {
			dpy[i] = Math.max(dpy[i], dpy[i + 1]);
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 1; i < n - 1; i++) {
			long ans = total + dpx[i - 1] + dpy[i + 1];
			pw.println(ans);
		}
		pw.flush();
	}
}
0