結果

問題 No.2028 Even Choice
ユーザー gr1msl3ygr1msl3y
提出日時 2022-08-16 00:12:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 351 ms / 2,000 ms
コード長 355 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 82,440 KB
実行使用メモリ 112,532 KB
最終ジャッジ日時 2024-04-10 10:38:52
合計ジャッジ時間 7,006 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 346 ms
102,024 KB
testcase_01 AC 300 ms
101,916 KB
testcase_02 AC 351 ms
102,432 KB
testcase_03 AC 125 ms
112,532 KB
testcase_04 AC 149 ms
112,020 KB
testcase_05 AC 185 ms
81,404 KB
testcase_06 AC 314 ms
103,860 KB
testcase_07 AC 187 ms
83,316 KB
testcase_08 AC 302 ms
95,672 KB
testcase_09 AC 275 ms
98,484 KB
testcase_10 AC 105 ms
83,276 KB
testcase_11 AC 216 ms
80,680 KB
testcase_12 AC 144 ms
78,168 KB
testcase_13 AC 188 ms
100,524 KB
testcase_14 AC 249 ms
83,312 KB
testcase_15 AC 42 ms
53,060 KB
testcase_16 AC 41 ms
53,032 KB
testcase_17 AC 42 ms
52,808 KB
testcase_18 AC 45 ms
54,320 KB
testcase_19 AC 48 ms
59,664 KB
testcase_20 AC 54 ms
63,172 KB
testcase_21 AC 52 ms
61,804 KB
testcase_22 AC 48 ms
58,888 KB
testcase_23 AC 43 ms
53,500 KB
testcase_24 AC 43 ms
52,340 KB
testcase_25 AC 43 ms
54,000 KB
testcase_26 AC 42 ms
53,492 KB
testcase_27 AC 43 ms
52,936 KB
testcase_28 AC 92 ms
95,744 KB
testcase_29 AC 78 ms
86,316 KB
testcase_30 AC 70 ms
77,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq as hq
N, K = map(int, input().split())
A = list(map(int, input().split()))
task = []
s = 0
ans = 0


def push(x):
    global s
    hq.heappush(task, x)
    s += x
    if len(task) >= K:
        s -= hq.heappop(task)


for i in range(N//2*2-1, 0, -2):
    if i+1 < N:
        push(A[i+1])
    ans = max(ans, s+A[i])
    push(A[i])

print(ans)
0