結果

問題 No.2028 Even Choice
ユーザー hir355hir355
提出日時 2022-08-05 22:04:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 369 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 112,348 KB
最終ジャッジ日時 2024-09-15 18:54:22
合計ジャッジ時間 5,235 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 234 ms
101,760 KB
testcase_01 AC 210 ms
102,072 KB
testcase_02 AC 239 ms
101,760 KB
testcase_03 AC 115 ms
112,348 KB
testcase_04 AC 135 ms
111,192 KB
testcase_05 AC 126 ms
80,840 KB
testcase_06 AC 216 ms
103,936 KB
testcase_07 AC 133 ms
83,264 KB
testcase_08 AC 195 ms
94,976 KB
testcase_09 AC 184 ms
98,008 KB
testcase_10 AC 82 ms
82,776 KB
testcase_11 AC 140 ms
80,256 KB
testcase_12 AC 129 ms
77,744 KB
testcase_13 AC 148 ms
101,120 KB
testcase_14 AC 157 ms
82,816 KB
testcase_15 AC 40 ms
52,352 KB
testcase_16 AC 40 ms
52,736 KB
testcase_17 AC 41 ms
52,352 KB
testcase_18 AC 43 ms
52,736 KB
testcase_19 AC 46 ms
58,496 KB
testcase_20 AC 53 ms
61,824 KB
testcase_21 AC 49 ms
60,672 KB
testcase_22 AC 46 ms
58,752 KB
testcase_23 AC 41 ms
52,224 KB
testcase_24 AC 41 ms
52,352 KB
testcase_25 AC 41 ms
52,352 KB
testcase_26 AC 40 ms
52,480 KB
testcase_27 AC 39 ms
52,224 KB
testcase_28 AC 80 ms
92,928 KB
testcase_29 AC 71 ms
83,072 KB
testcase_30 AC 63 ms
75,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
hq = []
for i in range(n - k + 1, n):
    ans += a[i]
    heapq.heappush(hq, a[i])
res = 0
for i in range(n - k, -1, -1):
    if i % 2:
        if res < ans + a[i]:
            res = ans + a[i]
    ans += a[i]
    heapq.heappush(hq, a[i])
    ans -= heapq.heappop(hq)
print(res)
0