結果

問題 No.1375 Divide and Update
ユーザー rlangevin
提出日時 2023-03-14 12:50:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 643 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 81,816 KB
実行使用メモリ 132,036 KB
最終ジャッジ日時 2024-09-18 08:00:18
合計ジャッジ時間 5,567 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *

def f(X):
    V = [-10**18] * (N - 2)
    Q = deque()
    val = 0
    for i in range(N - 2):
        Q.append(X[i])
        val += X[i]
        while len(Q) >= 2 and (val < 0 or Q[0] < 0):
            val -= Q.popleft()
            V[i] = max(V[i], val)
        V[i] = max(V[i], val)
    
    for i in range(1, N - 2):
        V[i] = max(V[i], V[i - 1])

    return V

N, X, Y = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(lambda x : X - x, A))
C = list(map(lambda x : Y - x, A))
C.reverse()
V1, V2 = f(B), f(C)
V2.reverse()
S = sum(A)
for i in range(N-2):
    print(S + V1[i] + V2[i])
0