結果

問題 No.2028 Even Choice
ユーザー Kiri8128Kiri8128
提出日時 2022-08-05 22:42:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 254 ms / 2,000 ms
コード長 489 bytes
コンパイル時間 1,201 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 104,812 KB
最終ジャッジ日時 2023-10-14 00:13:41
合計ジャッジ時間 7,510 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 254 ms
96,620 KB
testcase_01 AC 249 ms
99,260 KB
testcase_02 AC 247 ms
95,520 KB
testcase_03 AC 133 ms
104,812 KB
testcase_04 AC 137 ms
103,088 KB
testcase_05 AC 161 ms
80,384 KB
testcase_06 AC 237 ms
94,864 KB
testcase_07 AC 169 ms
81,636 KB
testcase_08 AC 200 ms
89,000 KB
testcase_09 AC 218 ms
90,364 KB
testcase_10 AC 115 ms
81,788 KB
testcase_11 AC 171 ms
80,188 KB
testcase_12 AC 155 ms
78,440 KB
testcase_13 AC 194 ms
93,860 KB
testcase_14 AC 185 ms
81,956 KB
testcase_15 AC 79 ms
71,444 KB
testcase_16 AC 78 ms
71,260 KB
testcase_17 AC 78 ms
71,380 KB
testcase_18 AC 80 ms
71,552 KB
testcase_19 AC 79 ms
71,288 KB
testcase_20 AC 85 ms
75,416 KB
testcase_21 AC 83 ms
75,164 KB
testcase_22 AC 84 ms
75,384 KB
testcase_23 AC 79 ms
71,300 KB
testcase_24 AC 78 ms
70,996 KB
testcase_25 AC 77 ms
71,116 KB
testcase_26 AC 79 ms
71,184 KB
testcase_27 AC 78 ms
71,440 KB
testcase_28 AC 107 ms
89,364 KB
testcase_29 AC 97 ms
84,584 KB
testcase_30 AC 94 ms
80,972 KB
権限があれば一括ダウンロードができます

ソースコード

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 K > 1 and a > m:
        hpush(a)
        hpop()
        s += a - m
    
print(ans)
0