結果

問題 No.2028 Even Choice
ユーザー asumo0729asumo0729
提出日時 2022-08-06 12:27:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 245 ms / 2,000 ms
コード長 464 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 118,804 KB
最終ジャッジ日時 2023-10-14 14:00:34
合計ジャッジ時間 6,225 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 244 ms
106,388 KB
testcase_01 AC 222 ms
106,704 KB
testcase_02 AC 245 ms
106,872 KB
testcase_03 AC 134 ms
117,032 KB
testcase_04 AC 164 ms
118,804 KB
testcase_05 AC 151 ms
82,108 KB
testcase_06 AC 230 ms
101,112 KB
testcase_07 AC 149 ms
84,496 KB
testcase_08 AC 195 ms
95,828 KB
testcase_09 AC 197 ms
95,416 KB
testcase_10 AC 105 ms
83,924 KB
testcase_11 AC 149 ms
81,392 KB
testcase_12 AC 142 ms
78,496 KB
testcase_13 AC 174 ms
97,688 KB
testcase_14 AC 161 ms
84,440 KB
testcase_15 AC 72 ms
71,304 KB
testcase_16 AC 71 ms
71,252 KB
testcase_17 AC 71 ms
71,364 KB
testcase_18 AC 76 ms
75,456 KB
testcase_19 AC 74 ms
70,976 KB
testcase_20 AC 82 ms
75,908 KB
testcase_21 AC 81 ms
75,556 KB
testcase_22 AC 77 ms
75,368 KB
testcase_23 AC 70 ms
71,112 KB
testcase_24 AC 72 ms
71,524 KB
testcase_25 AC 70 ms
71,376 KB
testcase_26 AC 71 ms
71,248 KB
testcase_27 AC 70 ms
71,364 KB
testcase_28 AC 131 ms
95,708 KB
testcase_29 AC 119 ms
90,052 KB
testcase_30 AC 113 ms
84,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush
N, K = map(int, input().split())
A = list(map(int, input().split()))
hp = []
heapify(hp)
s = 0
ans = 0

for i in range(N - 1, -1, -1):
    if (N - 1 - i) < K -1:
        heappush(hp, A[i])
        s += A[i]
    else:
        if i & 1:
            while len(hp) != K - 1:
                a = heappop(hp)
                s -= a
            ans = max(ans, s + A[i])
        heappush(hp, A[i])
        s += A[i] 
print(ans)
0