結果

問題 No.2028 Even Choice
ユーザー EguyEguy
提出日時 2022-08-05 21:38:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 685 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 119,956 KB
最終ジャッジ日時 2023-10-13 22:13:56
合計ジャッジ時間 6,581 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 274 ms
107,908 KB
testcase_01 AC 245 ms
108,096 KB
testcase_02 AC 278 ms
108,360 KB
testcase_03 AC 150 ms
118,056 KB
testcase_04 AC 176 ms
119,956 KB
testcase_05 AC 165 ms
83,048 KB
testcase_06 AC 271 ms
102,500 KB
testcase_07 AC 162 ms
85,196 KB
testcase_08 AC 225 ms
97,596 KB
testcase_09 AC 217 ms
96,348 KB
testcase_10 AC 127 ms
85,200 KB
testcase_11 AC 164 ms
81,544 KB
testcase_12 AC 146 ms
78,636 KB
testcase_13 AC 185 ms
98,436 KB
testcase_14 AC 175 ms
85,128 KB
testcase_15 AC 78 ms
71,032 KB
testcase_16 AC 76 ms
70,944 KB
testcase_17 AC 77 ms
70,880 KB
testcase_18 AC 80 ms
74,656 KB
testcase_19 AC 78 ms
71,148 KB
testcase_20 AC 90 ms
75,552 KB
testcase_21 AC 87 ms
75,224 KB
testcase_22 AC 83 ms
75,096 KB
testcase_23 WA -
testcase_24 AC 79 ms
71,016 KB
testcase_25 WA -
testcase_26 AC 80 ms
71,104 KB
testcase_27 AC 80 ms
70,904 KB
testcase_28 WA -
testcase_29 AC 103 ms
89,092 KB
testcase_30 AC 96 ms
83,488 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:
    print(max(A[1:]))
    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