結果

問題 No.999 てん vs. ほむ
ユーザー 学ぶマン
提出日時 2025-05-01 17:58:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 442 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 82,120 KB
実行使用メモリ 124,048 KB
最終ジャッジ日時 2025-05-01 17:58:48
合計ジャッジ時間 4,342 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))

memo = []
for i in range(N):
    l, r = A[2*i], A[2*i + 1]
    memo.append(l - r)

# 左から累積
memo_l = list(accumulate(memo, initial=0))

# 右から累積
memo_r = [0]
for i in range(N - 1, -1, -1):
    memo_r.append(memo_r[-1] - memo[i])
memo_r.reverse()

ansl = []
for i in range(N + 1):
    ansl.append(memo_l[i] + memo_r[i])

print(max(ansl))
0