結果

問題 No.2028 Even Choice
ユーザー tassei903tassei903
提出日時 2022-08-08 07:21:35
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 898 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 81,540 KB
実行使用メモリ 118,660 KB
最終ジャッジ日時 2023-10-18 22:39:12
合計ジャッジ時間 6,742 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 276 ms
106,492 KB
testcase_01 AC 239 ms
106,648 KB
testcase_02 AC 278 ms
106,684 KB
testcase_03 AC 125 ms
118,660 KB
testcase_04 AC 144 ms
117,784 KB
testcase_05 AC 152 ms
81,472 KB
testcase_06 AC 236 ms
103,752 KB
testcase_07 AC 141 ms
83,656 KB
testcase_08 AC 219 ms
98,204 KB
testcase_09 AC 210 ms
101,476 KB
testcase_10 AC 102 ms
83,380 KB
testcase_11 AC 167 ms
80,124 KB
testcase_12 AC 123 ms
76,804 KB
testcase_13 AC 176 ms
104,912 KB
testcase_14 AC 177 ms
83,704 KB
testcase_15 AC 40 ms
53,380 KB
testcase_16 AC 39 ms
53,380 KB
testcase_17 AC 39 ms
53,380 KB
testcase_18 AC 45 ms
59,040 KB
testcase_19 AC 44 ms
55,428 KB
testcase_20 AC 53 ms
63,620 KB
testcase_21 AC 49 ms
61,316 KB
testcase_22 AC 45 ms
59,044 KB
testcase_23 RE -
testcase_24 AC 40 ms
53,380 KB
testcase_25 AC 41 ms
53,380 KB
testcase_26 AC 41 ms
53,380 KB
testcase_27 AC 39 ms
53,380 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

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[i])

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