結果

問題 No.1375 Divide and Update
ユーザー rlangevinrlangevin
提出日時 2023-03-14 12:50:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 643 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 81,640 KB
実行使用メモリ 132,380 KB
最終ジャッジ日時 2023-10-18 11:36:49
合計ジャッジ時間 6,174 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,572 KB
testcase_01 AC 43 ms
55,572 KB
testcase_02 AC 42 ms
55,572 KB
testcase_03 AC 42 ms
55,572 KB
testcase_04 AC 42 ms
55,572 KB
testcase_05 AC 42 ms
55,572 KB
testcase_06 AC 42 ms
55,572 KB
testcase_07 AC 42 ms
55,572 KB
testcase_08 AC 42 ms
55,572 KB
testcase_09 AC 42 ms
55,572 KB
testcase_10 AC 177 ms
123,316 KB
testcase_11 AC 144 ms
101,136 KB
testcase_12 AC 123 ms
99,908 KB
testcase_13 AC 121 ms
97,392 KB
testcase_14 AC 196 ms
131,276 KB
testcase_15 AC 195 ms
131,280 KB
testcase_16 AC 191 ms
129,836 KB
testcase_17 AC 179 ms
129,740 KB
testcase_18 AC 172 ms
131,700 KB
testcase_19 AC 173 ms
131,708 KB
testcase_20 AC 158 ms
132,380 KB
権限があれば一括ダウンロードができます

ソースコード

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