結果

問題 No.2028 Even Choice
ユーザー Kiri8128Kiri8128
提出日時 2022-08-05 22:39:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 479 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 86,996 KB
実行使用メモリ 104,936 KB
最終ジャッジ日時 2023-10-14 00:08:50
合計ジャッジ時間 6,344 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 253 ms
96,684 KB
testcase_01 AC 247 ms
98,976 KB
testcase_02 AC 249 ms
95,284 KB
testcase_03 AC 135 ms
104,936 KB
testcase_04 AC 139 ms
103,356 KB
testcase_05 AC 165 ms
80,356 KB
testcase_06 AC 238 ms
94,980 KB
testcase_07 AC 170 ms
81,688 KB
testcase_08 AC 199 ms
89,284 KB
testcase_09 AC 218 ms
90,200 KB
testcase_10 AC 114 ms
81,648 KB
testcase_11 AC 166 ms
80,356 KB
testcase_12 AC 150 ms
78,608 KB
testcase_13 AC 191 ms
94,028 KB
testcase_14 AC 184 ms
81,664 KB
testcase_15 AC 77 ms
71,372 KB
testcase_16 AC 78 ms
71,016 KB
testcase_17 AC 76 ms
71,296 KB
testcase_18 AC 78 ms
71,088 KB
testcase_19 AC 77 ms
71,416 KB
testcase_20 AC 84 ms
75,376 KB
testcase_21 AC 85 ms
75,368 KB
testcase_22 AC 83 ms
75,676 KB
testcase_23 WA -
testcase_24 AC 78 ms
71,364 KB
testcase_25 WA -
testcase_26 AC 77 ms
71,296 KB
testcase_27 AC 78 ms
71,112 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop

H = []
hpush = lambda x: heappush(H, x)
hpop = lambda: heappop(H)
hmin = lambda: H[0] if H else 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:
        hpush(a)
        hpop()
        s += a - m
    
print(ans)
0