結果

問題 No.2028 Even Choice
ユーザー EguyEguy
提出日時 2022-08-05 21:40:49
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 740 bytes
コンパイル時間 998 ms
コンパイル使用メモリ 86,432 KB
実行使用メモリ 120,068 KB
最終ジャッジ日時 2023-10-13 22:17:10
合計ジャッジ時間 7,402 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 265 ms
107,796 KB
testcase_01 AC 237 ms
108,392 KB
testcase_02 AC 268 ms
108,132 KB
testcase_03 AC 145 ms
118,472 KB
testcase_04 AC 170 ms
120,068 KB
testcase_05 AC 156 ms
83,092 KB
testcase_06 AC 258 ms
102,484 KB
testcase_07 AC 155 ms
84,940 KB
testcase_08 AC 216 ms
97,700 KB
testcase_09 AC 209 ms
95,996 KB
testcase_10 AC 117 ms
85,136 KB
testcase_11 AC 158 ms
81,324 KB
testcase_12 AC 141 ms
78,748 KB
testcase_13 AC 182 ms
98,572 KB
testcase_14 AC 169 ms
85,248 KB
testcase_15 AC 73 ms
71,032 KB
testcase_16 AC 74 ms
71,044 KB
testcase_17 AC 76 ms
71,252 KB
testcase_18 AC 80 ms
74,964 KB
testcase_19 AC 77 ms
70,884 KB
testcase_20 AC 88 ms
75,624 KB
testcase_21 AC 84 ms
75,384 KB
testcase_22 AC 80 ms
75,260 KB
testcase_23 RE -
testcase_24 AC 75 ms
71,036 KB
testcase_25 RE -
testcase_26 AC 73 ms
71,252 KB
testcase_27 AC 74 ms
70,884 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, math
sys.setrecursionlimit(1000000)
INF = 1 << 100
#mod = 1000000007
mod = 998244353
input = lambda: sys.stdin.readline().rstrip()
li = lambda: list(map(int, input().split()))
from heapq import *

N, K = li()
A = li()

if K == 1:
    ans = -INF
    for i in range(1, N, 2):
        ans = max(ans, A[i])
    print(ans)

hq = []
su = 0
acc = [-INF] * N
for i in range(N)[::-1]:
    a = A[i]
    if len(hq) == K-1:
        x = heappop(hq)
        if x > a:
            heappush(hq, x)
        else:
            heappush(hq, a)
            su += a - x
    else:
        su += a
        heappush(hq, a)
    if len(hq) == K-1:
        acc[i] = su

ans = -INF
for i in range(1, N-1, 2):
    ans = max(ans, A[i] + acc[i+1])

print(ans)
0