結果

問題 No.2028 Even Choice
ユーザー Kiri8128Kiri8128
提出日時 2022-08-05 22:37:19
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 467 bytes
コンパイル時間 1,143 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 105,040 KB
最終ジャッジ日時 2023-10-14 00:01:32
合計ジャッジ時間 6,753 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 248 ms
96,484 KB
testcase_01 AC 236 ms
99,184 KB
testcase_02 AC 239 ms
95,412 KB
testcase_03 AC 133 ms
105,040 KB
testcase_04 AC 135 ms
103,516 KB
testcase_05 AC 162 ms
80,276 KB
testcase_06 AC 235 ms
94,776 KB
testcase_07 AC 163 ms
81,624 KB
testcase_08 AC 192 ms
89,004 KB
testcase_09 AC 209 ms
90,232 KB
testcase_10 AC 113 ms
81,808 KB
testcase_11 AC 167 ms
80,236 KB
testcase_12 AC 148 ms
78,736 KB
testcase_13 AC 189 ms
94,348 KB
testcase_14 AC 182 ms
81,900 KB
testcase_15 AC 78 ms
71,252 KB
testcase_16 AC 78 ms
71,264 KB
testcase_17 AC 78 ms
71,376 KB
testcase_18 AC 80 ms
71,372 KB
testcase_19 AC 79 ms
71,500 KB
testcase_20 AC 87 ms
75,452 KB
testcase_21 AC 86 ms
75,420 KB
testcase_22 AC 85 ms
75,612 KB
testcase_23 RE -
testcase_24 AC 78 ms
71,280 KB
testcase_25 RE -
testcase_26 AC 79 ms
71,372 KB
testcase_27 AC 77 ms
71,148 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop

H = []
hpush = lambda x: heappush(H, x)
hpop = lambda: heappop(H)
hmin = lambda: H[0]

N, K = map(int, input().split())
A = [int(a) for a in input().split()]
s = 0
for i in range(N - K + 1, N):
    a = A[i]
    s += a
    hpush(a)

ans = 0
for i in range(N - K + 1)[::-1]:
    a = A[i]
    if i % 2:
        ans = max(ans, s + a)
    
    m = hmin()
    if a > m:
        hpop()
        hpush(a)
        s += a - m
    
print(ans)
0