結果
問題 | No.3103 Butterfly Effect |
ユーザー |
![]() |
提出日時 | 2025-04-15 21:37:01 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 728 bytes |
コンパイル時間 | 1,175 ms |
コンパイル使用メモリ | 82,520 KB |
実行使用メモリ | 67,800 KB |
最終ジャッジ日時 | 2025-04-15 21:39:02 |
合計ジャッジ時間 | 6,774 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 1 |
other | RE * 50 |
ソースコード
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)