結果
| 問題 | No.999 てん vs. ほむ |
| コンテスト | |
| ユーザー |
FromBooska
|
| 提出日時 | 2023-04-21 11:13:13 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 118 ms / 2,000 ms |
| コード長 | 898 bytes |
| 記録 | |
| コンパイル時間 | 180 ms |
| コンパイル使用メモリ | 85,244 KB |
| 実行使用メモリ | 128,384 KB |
| 最終ジャッジ日時 | 2026-05-06 09:57:04 |
| 合計ジャッジ時間 | 3,801 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
# 区間dpだと間に合わない、左右からの累積和で解ける
# 左からのネット得点累積和、右からのネット得点累積和
# どこまで左、どこまで右なら最大値となるか
N = int(input())
A = list(map(int, input().split()))
from_left = []
for i in range(N):
calc = A[i*2]-A[i*2+1]
from_left.append(calc)
from_left_cumu = [0]
temp = 0
for i in range(N):
temp += from_left[i]
from_left_cumu.append(temp)
#print(from_left)
#print(from_left_cumu)
from_right = []
for i in range(N):
calc = A[N*2-i*2-1]-A[N*2-i*2-2]
from_right.append(calc)
from_right_cumu = [0]
temp = 0
for i in range(N):
temp += from_right[i]
from_right_cumu.append(temp)
from_right_cumu.reverse()
#print(from_right)
#print(from_right_cumu)
ans = -10**20
for i in range(N+1):
ans = max(ans, from_left_cumu[i]+from_right_cumu[i])
print(ans)
FromBooska