結果

問題 No.2028 Even Choice
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-08-05 22:06:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 528 bytes
コンパイル時間 1,426 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 118,360 KB
最終ジャッジ日時 2023-10-13 23:08:46
合計ジャッジ時間 7,285 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 249 ms
105,308 KB
testcase_01 AC 228 ms
105,548 KB
testcase_02 AC 249 ms
105,724 KB
testcase_03 AC 133 ms
116,816 KB
testcase_04 AC 157 ms
118,360 KB
testcase_05 AC 155 ms
82,260 KB
testcase_06 AC 236 ms
100,088 KB
testcase_07 AC 154 ms
83,672 KB
testcase_08 AC 206 ms
95,196 KB
testcase_09 AC 213 ms
94,268 KB
testcase_10 AC 118 ms
83,992 KB
testcase_11 AC 157 ms
80,912 KB
testcase_12 AC 138 ms
78,112 KB
testcase_13 AC 177 ms
96,512 KB
testcase_14 AC 168 ms
84,068 KB
testcase_15 AC 69 ms
70,640 KB
testcase_16 AC 69 ms
70,920 KB
testcase_17 AC 72 ms
70,644 KB
testcase_18 AC 77 ms
74,804 KB
testcase_19 AC 73 ms
70,820 KB
testcase_20 AC 84 ms
75,436 KB
testcase_21 AC 81 ms
75,456 KB
testcase_22 AC 76 ms
75,184 KB
testcase_23 AC 68 ms
70,780 KB
testcase_24 AC 70 ms
71,172 KB
testcase_25 AC 68 ms
71,024 KB
testcase_26 AC 70 ms
70,944 KB
testcase_27 AC 71 ms
71,296 KB
testcase_28 AC 146 ms
95,160 KB
testcase_29 AC 129 ms
89,672 KB
testcase_30 AC 121 ms
84,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush

n,k = map(int,input().split())
A = list(map(int,input().split()))

ans = 0

score = 0
size = 0
h = []

for i in range(n)[::-1]:
    a = A[i]
    if i%2 == 0:
        size += 1
        heappush(h,a)
        score += a

        continue
    # print(i,a,h,score)
    while size > k:
        x = heappop(h)
        size -= 1
        score -= x
    if size == k:
        ans = max(ans,score+a-h[0])
    else:
        ans = max(ans,score+a)
    heappush(h,a)
    score += a
    size += 1
print(ans)
0