結果

問題 No.999 てん vs. ほむ
ユーザー FromBooskaFromBooska
提出日時 2023-04-21 11:13:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 898 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 82,564 KB
実行使用メモリ 124,012 KB
最終ジャッジ日時 2024-04-24 01:02:53
合計ジャッジ時間 4,044 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
51,840 KB
testcase_01 AC 38 ms
51,840 KB
testcase_02 AC 42 ms
51,968 KB
testcase_03 AC 40 ms
51,968 KB
testcase_04 AC 40 ms
52,224 KB
testcase_05 AC 40 ms
52,096 KB
testcase_06 AC 40 ms
52,096 KB
testcase_07 AC 40 ms
52,096 KB
testcase_08 AC 54 ms
63,488 KB
testcase_09 AC 115 ms
104,576 KB
testcase_10 AC 70 ms
83,200 KB
testcase_11 AC 63 ms
76,288 KB
testcase_12 AC 79 ms
92,544 KB
testcase_13 AC 131 ms
123,360 KB
testcase_14 AC 130 ms
123,740 KB
testcase_15 AC 130 ms
124,012 KB
testcase_16 AC 129 ms
123,664 KB
testcase_17 AC 107 ms
113,664 KB
testcase_18 AC 105 ms
113,408 KB
testcase_19 AC 106 ms
114,176 KB
testcase_20 AC 106 ms
113,920 KB
testcase_21 AC 127 ms
123,428 KB
testcase_22 AC 116 ms
107,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 区間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)
0