結果

問題 No.1375 Divide and Update
ユーザー yuruhiyayuruhiya
提出日時 2021-02-06 17:56:53
言語 Ruby
(3.3.0)
結果
AC  
実行時間 393 ms / 2,000 ms
コード長 357 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 11,448 KB
実行使用メモリ 40,804 KB
最終ジャッジ日時 2023-09-16 04:02:17
合計ジャッジ時間 7,348 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,132 KB
testcase_01 AC 82 ms
15,236 KB
testcase_02 AC 82 ms
15,132 KB
testcase_03 AC 85 ms
15,256 KB
testcase_04 AC 80 ms
15,112 KB
testcase_05 AC 80 ms
15,140 KB
testcase_06 AC 80 ms
15,164 KB
testcase_07 AC 83 ms
15,044 KB
testcase_08 AC 84 ms
15,284 KB
testcase_09 AC 83 ms
15,280 KB
testcase_10 AC 357 ms
39,244 KB
testcase_11 AC 334 ms
36,932 KB
testcase_12 AC 219 ms
24,344 KB
testcase_13 AC 201 ms
23,696 KB
testcase_14 AC 393 ms
40,396 KB
testcase_15 AC 389 ms
40,468 KB
testcase_16 AC 388 ms
40,396 KB
testcase_17 AC 389 ms
40,540 KB
testcase_18 AC 391 ms
40,804 KB
testcase_19 AC 393 ms
40,612 KB
testcase_20 AC 377 ms
39,096 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def func(n, a, x)
	dp = [-10**9] * -~n
	n.times { |i| dp[i + 1] = (x - a[i]) + [dp[i], 0].max }
	n.times { |i| dp[i + 1] = [dp[i + 1], dp[i]].max }
	dp
end

n, x, y = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
left = func(n, a, x)
right = func(n, a.reverse, y).reverse
sum = a.sum
puts (1...n - 1).map { |i| sum + left[i] + right[i + 1] }.join("\n")
0