結果

問題 No.2028 Even Choice
ユーザー EguyEguy
提出日時 2022-08-05 21:41:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 751 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 87,280 KB
実行使用メモリ 120,120 KB
最終ジャッジ日時 2023-10-13 22:17:53
合計ジャッジ時間 6,360 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 247 ms
108,132 KB
testcase_01 AC 226 ms
108,692 KB
testcase_02 AC 249 ms
108,712 KB
testcase_03 AC 141 ms
118,840 KB
testcase_04 AC 166 ms
120,120 KB
testcase_05 AC 150 ms
83,368 KB
testcase_06 AC 248 ms
102,704 KB
testcase_07 AC 150 ms
85,544 KB
testcase_08 AC 214 ms
97,936 KB
testcase_09 AC 208 ms
96,568 KB
testcase_10 AC 118 ms
85,488 KB
testcase_11 AC 161 ms
81,816 KB
testcase_12 AC 140 ms
79,048 KB
testcase_13 AC 177 ms
98,652 KB
testcase_14 AC 166 ms
85,620 KB
testcase_15 AC 71 ms
71,664 KB
testcase_16 AC 73 ms
71,208 KB
testcase_17 AC 73 ms
71,484 KB
testcase_18 AC 75 ms
74,808 KB
testcase_19 AC 75 ms
71,284 KB
testcase_20 AC 84 ms
75,888 KB
testcase_21 AC 82 ms
75,708 KB
testcase_22 AC 77 ms
75,472 KB
testcase_23 AC 74 ms
71,608 KB
testcase_24 AC 75 ms
71,460 KB
testcase_25 AC 72 ms
71,604 KB
testcase_26 AC 74 ms
71,204 KB
testcase_27 AC 73 ms
71,324 KB
testcase_28 AC 103 ms
96,472 KB
testcase_29 AC 91 ms
89,356 KB
testcase_30 AC 86 ms
83,796 KB
権限があれば一括ダウンロードができます

ソースコード

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)
    exit()

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