結果
問題 |
No.1375 Divide and Update
|
ユーザー |
![]() |
提出日時 | 2025-03-20 18:46:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 150 ms / 2,000 ms |
コード長 | 1,657 bytes |
コンパイル時間 | 136 ms |
コンパイル使用メモリ | 82,172 KB |
実行使用メモリ | 141,712 KB |
最終ジャッジ日時 | 2025-03-20 18:47:04 |
合計ジャッジ時間 | 4,351 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
ソースコード
def main(): import sys input = sys.stdin.read().split() idx = 0 N = int(input[idx]) idx += 1 X = int(input[idx]) idx += 1 Y = int(input[idx]) idx += 1 a = list(map(int, input[idx:idx + N])) idx += N S = sum(a) x_gain = [X - num for num in a] y_gain = [Y - num for num in a] # Compute left_max using Kadane's algorithm left_max = [0] * (N + 2) # 1-based indexing, up to N current_max = 0 max_so_far = -float('inf') for i in range(1, N + 1): current_max = max(x_gain[i - 1], current_max + x_gain[i - 1]) if current_max > max_so_far: max_so_far = current_max left_max[i] = max_so_far # Compute right_max using Kadane's algorithm from right right_max = [0] * (N + 2) current_max = 0 max_so_far = -float('inf') for i in range(N, 0, -1): current_max = max(y_gain[i - 1], current_max + y_gain[i - 1]) if current_max > max_so_far: max_so_far = current_max right_max[i] = max_so_far # For each M from 2 to N-1 (M is from 2 to N-1) # M starts from 2, and in the problem, outputs M = i+1 (for i from 1 to N-2) results = [] for M in range(2, N): left_part = M - 1 right_part = M + 1 if left_part < 1: gain_left = 0 else: gain_left = left_max[left_part] if right_part > N: gain_right = 0 else: gain_right = right_max[right_part] total = S + gain_left + gain_right results.append(total) print('\n'.join(map(str, results))) if __name__ == '__main__': main()