結果

問題 No.1375 Divide and Update
コンテスト
ユーザー LyricalMaestro
提出日時 2026-09-16 00:29:33
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 111 ms / 2,000 ms
+ 271µs
コード長 1,526 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 66 ms
コンパイル使用メモリ 80,812 KB
実行使用メモリ 117,692 KB
最終ジャッジ日時 2026-09-16 00:29:41
合計ジャッジ時間 5,518 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

## https://yukicoder.me/problems/no/1375


def main():
    N, X, Y = map(int, input().split())
    A = list(map(int, input().split()))

    dp = [-1] * 4
    dp[0] = 0
    answers = [0] * N
    for i in range(N):
        a = A[i]
        new_dp = dp.copy()

        # 0 から
        if dp[0] >= 0:
            new_dp[0] = max(new_dp[0], dp[0] + a)
            new_dp[1] = max(new_dp[1], dp[0] + X)

        # 1 から
        if dp[1] >= 0:
            new_dp[1] = max(new_dp[1], dp[1] + X)
            new_dp[2] = max(new_dp[2], dp[1] + a)
            new_dp[3] = max(new_dp[3], dp[1])

        if dp[2] >= 0:
            new_dp[2] = max(new_dp[2], dp[2] + a)
            new_dp[3] = max(new_dp[3], dp[2])

        dp = new_dp
        answers[i] = dp[3]
    dp = [-1] * 5
    dp[0] = 0
    answers2 = [0] * N
    for i in reversed(range(N)):
        a = A[i]
        new_dp = dp.copy()

        # 0 から
        if dp[0] >= 0:
            new_dp[0] = max(new_dp[0], dp[0] + a)
            new_dp[1] = max(new_dp[1], dp[0] + Y)

        # 1 から
        if dp[1] >= 0:
            new_dp[1] = max(new_dp[1], dp[1] + Y)
            new_dp[2] = max(new_dp[2], dp[1] + a)
            new_dp[3] = max(new_dp[3], dp[1])

        if dp[2] >= 0:
            new_dp[2] = max(new_dp[2], dp[2] + a)
            new_dp[3] = max(new_dp[3], dp[2])

        dp = new_dp
        answers2[i] = dp[3]

    for i in range(1, N - 1):
        ans = answers[i] + answers2[i] + A[i]
        print(ans)



if __name__ == "__main__":
    main()
0