結果

問題 No.3103 Butterfly Effect
ユーザー lam6er
提出日時 2025-04-15 21:34:07
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 728 bytes
コンパイル時間 436 ms
コンパイル使用メモリ 82,484 KB
実行使用メモリ 67,404 KB
最終ジャッジ日時 2025-04-15 21:36:25
合計ジャッジ時間 7,720 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 1
other RE * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int, input().split()))
original_sum = sum(abs(x) for x in a)

if n == 0:
    print(0)
    exit()

max_val = max(a)
pos = a.index(max_val)

# Calculate contributions
contributions = [abs(max_val) - abs(x) for x in a]

# Compute max_ending_at_pos (left part)
max_ending = 0
current = 0
for i in range(pos - 1, -1, -1):
    current += contributions[i]
    if current > max_ending:
        max_ending = current

# Compute max_starting_at_pos (right part)
max_starting = 0
current = 0
for i in range(pos + 1, n):
    current += contributions[i]
    if current > max_starting:
        max_starting = current

total_gain = max_ending + max_starting
answer = original_sum + max(total_gain, 0)
print(answer)
0