結果

問題 No.999 てん vs. ほむ
ユーザー 双六双六
提出日時 2020-07-21 23:26:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 688 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 86,728 KB
実行使用メモリ 109,032 KB
最終ジャッジ日時 2023-08-30 05:14:52
合計ジャッジ時間 4,604 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,532 KB
testcase_01 AC 94 ms
71,476 KB
testcase_02 AC 94 ms
71,420 KB
testcase_03 AC 94 ms
71,596 KB
testcase_04 AC 95 ms
71,652 KB
testcase_05 AC 92 ms
71,532 KB
testcase_06 AC 94 ms
71,740 KB
testcase_07 AC 93 ms
71,600 KB
testcase_08 AC 105 ms
77,280 KB
testcase_09 AC 139 ms
105,240 KB
testcase_10 AC 112 ms
84,116 KB
testcase_11 AC 108 ms
81,440 KB
testcase_12 AC 117 ms
87,848 KB
testcase_13 AC 142 ms
108,960 KB
testcase_14 AC 142 ms
109,032 KB
testcase_15 AC 142 ms
108,768 KB
testcase_16 AC 141 ms
108,656 KB
testcase_17 AC 137 ms
104,752 KB
testcase_18 AC 133 ms
103,508 KB
testcase_19 AC 134 ms
103,496 KB
testcase_20 AC 134 ms
104,692 KB
testcase_21 AC 141 ms
108,668 KB
testcase_22 AC 140 ms
108,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	A = getlist()
	Lsum = [0] * N
	Rsum = [0] * N
	Lsum[0] = A[0] - A[1]
	Rsum[-1] = A[-1] - A[-2]
	for i in range(1, N):
		Lsum[i] = Lsum[i - 1] + A[2 * i] - A[2 * i + 1]
		Rsum[-1 - i] = Rsum[-i] + A[-1 - 2 * i] - A[-2 - 2 * i]

	if N == 1:
		print(abs(A[0] - A[1]))
		return

	ans = -INF
	for i in range(N - 1):
		ans = max(ans, Lsum[i] + Rsum[i + 1])

	ans = max(ans, Lsum[-1], Rsum[0])

	print(ans)



if __name__ == '__main__':
	main()
0