結果

問題 No.999 てん vs. ほむ
ユーザー ThetaTheta
提出日時 2022-10-21 14:24:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 754 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 10,936 KB
実行使用メモリ 33,452 KB
最終ジャッジ日時 2023-09-13 15:40:42
合計ジャッジ時間 2,936 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,420 KB
testcase_01 AC 16 ms
8,256 KB
testcase_02 AC 16 ms
8,256 KB
testcase_03 AC 16 ms
8,388 KB
testcase_04 AC 16 ms
8,224 KB
testcase_05 AC 16 ms
8,344 KB
testcase_06 AC 16 ms
8,272 KB
testcase_07 AC 16 ms
8,380 KB
testcase_08 AC 20 ms
9,328 KB
testcase_09 AC 123 ms
31,408 KB
testcase_10 AC 48 ms
15,268 KB
testcase_11 AC 37 ms
12,984 KB
testcase_12 AC 64 ms
18,660 KB
testcase_13 AC 137 ms
33,452 KB
testcase_14 AC 137 ms
33,068 KB
testcase_15 AC 138 ms
33,368 KB
testcase_16 AC 139 ms
33,344 KB
testcase_17 AC 120 ms
30,888 KB
testcase_18 AC 119 ms
30,544 KB
testcase_19 AC 120 ms
30,384 KB
testcase_20 AC 122 ms
30,064 KB
testcase_21 AC 116 ms
30,064 KB
testcase_22 AC 112 ms
29,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import accumulate
from math import inf


def main():
    N = int(input())
    cards = list(map(int, input().split()))

    left_score = []
    for idx in range(0, 2*N, 2):
        left_score.append(cards[idx] - cards[idx+1])

    right_score = reversed(list(map(lambda num: -num, left_score)))

    left_score_partial_sum = list(accumulate(left_score))
    right_score_partial_sum = list(accumulate(right_score))
    right_score_partial_sum.reverse()

    maximum = max(right_score_partial_sum[0], left_score_partial_sum[-1])
    for idx in range(N-1):
        maximum = max(
            maximum,
            left_score_partial_sum[idx] + right_score_partial_sum[idx+1]
        )
    print(maximum)


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