結果

問題 No.2028 Even Choice
ユーザー tassei903tassei903
提出日時 2022-08-08 07:23:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 265 ms / 2,000 ms
コード長 899 bytes
コンパイル時間 752 ms
コンパイル使用メモリ 81,508 KB
実行使用メモリ 118,728 KB
最終ジャッジ日時 2023-10-18 22:40:29
合計ジャッジ時間 5,632 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 253 ms
106,556 KB
testcase_01 AC 236 ms
106,712 KB
testcase_02 AC 265 ms
106,748 KB
testcase_03 AC 122 ms
118,728 KB
testcase_04 AC 143 ms
117,848 KB
testcase_05 AC 142 ms
81,540 KB
testcase_06 AC 238 ms
103,840 KB
testcase_07 AC 141 ms
83,724 KB
testcase_08 AC 215 ms
98,276 KB
testcase_09 AC 205 ms
101,548 KB
testcase_10 AC 99 ms
83,468 KB
testcase_11 AC 170 ms
80,180 KB
testcase_12 AC 122 ms
76,872 KB
testcase_13 AC 176 ms
104,996 KB
testcase_14 AC 171 ms
83,772 KB
testcase_15 AC 38 ms
53,420 KB
testcase_16 AC 38 ms
53,420 KB
testcase_17 AC 38 ms
53,420 KB
testcase_18 AC 45 ms
59,124 KB
testcase_19 AC 42 ms
55,468 KB
testcase_20 AC 52 ms
63,700 KB
testcase_21 AC 48 ms
61,400 KB
testcase_22 AC 45 ms
59,128 KB
testcase_23 AC 39 ms
53,420 KB
testcase_24 AC 39 ms
53,420 KB
testcase_25 AC 39 ms
53,420 KB
testcase_26 AC 39 ms
53,420 KB
testcase_27 AC 38 ms
53,420 KB
testcase_28 AC 104 ms
98,440 KB
testcase_29 AC 88 ms
90,484 KB
testcase_30 AC 80 ms
83,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
from heapq import *
ans = 0
n,k = na()
k-=1
a = na()
b = [-float("inf")]
for i in range(1,n,2):
    b.append(max(b[-1],a[i]))
s = 0
hq = []
if n % 2:
    hq.append(a[-1])
    s += a[-1]
    while len(hq) > k:
        x = heappop(hq)
        s-=x
    if len(hq) == k:
        ans = max(ans, s + b[-1])

for i in range(n//2-1,-1,-1):
    heappush(hq, a[i*2])
    s += a[i*2]
    heappush(hq, a[i*2+1])
    s += a[i*2 + 1]
    while len(hq) > k:
        x = heappop(hq)
        s-=x
    if len(hq) == k:
        ans = max(ans, s + b[i])

print(ans)
0