結果

問題 No.2028 Even Choice
ユーザー 👑 rin204rin204
提出日時 2022-08-20 15:19:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 302 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 112,156 KB
最終ジャッジ日時 2024-04-17 14:00:46
合計ジャッジ時間 6,029 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 248 ms
102,272 KB
testcase_01 AC 229 ms
101,632 KB
testcase_02 AC 261 ms
101,888 KB
testcase_03 AC 126 ms
112,156 KB
testcase_04 AC 149 ms
111,032 KB
testcase_05 AC 148 ms
80,768 KB
testcase_06 AC 237 ms
103,808 KB
testcase_07 AC 144 ms
82,560 KB
testcase_08 AC 211 ms
94,976 KB
testcase_09 AC 199 ms
98,048 KB
testcase_10 AC 93 ms
82,560 KB
testcase_11 AC 144 ms
80,000 KB
testcase_12 AC 130 ms
77,696 KB
testcase_13 AC 166 ms
100,864 KB
testcase_14 AC 164 ms
83,200 KB
testcase_15 AC 43 ms
52,224 KB
testcase_16 AC 43 ms
52,096 KB
testcase_17 AC 43 ms
52,096 KB
testcase_18 AC 46 ms
53,248 KB
testcase_19 AC 50 ms
58,240 KB
testcase_20 AC 58 ms
61,312 KB
testcase_21 AC 55 ms
60,800 KB
testcase_22 AC 50 ms
58,496 KB
testcase_23 AC 43 ms
52,096 KB
testcase_24 AC 43 ms
52,224 KB
testcase_25 AC 44 ms
52,608 KB
testcase_26 AC 43 ms
52,096 KB
testcase_27 AC 43 ms
52,480 KB
testcase_28 AC 90 ms
92,544 KB
testcase_29 AC 84 ms
82,688 KB
testcase_30 AC 71 ms
74,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

n, k = map(int, input().split())
A = list(map(int, input().split()))
tot = 0
hq = []
ans = 0
for i in range(n - 1, -1, -1):
    a = A[i]
    tot += a
    heappush(hq, a)
    if len(hq) == k:
        if i & 1:
            ans = max(ans, tot)
        tot -= heappop(hq)
print(ans)


0