結果

問題 No.2028 Even Choice
ユーザー 👑 KazunKazun
提出日時 2022-08-05 21:34:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 259 ms / 2,000 ms
コード長 289 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 121,348 KB
最終ジャッジ日時 2023-10-13 22:07:48
合計ジャッジ時間 5,885 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 246 ms
112,460 KB
testcase_01 AC 229 ms
112,504 KB
testcase_02 AC 259 ms
112,628 KB
testcase_03 AC 140 ms
120,472 KB
testcase_04 AC 163 ms
121,348 KB
testcase_05 AC 138 ms
83,732 KB
testcase_06 AC 240 ms
106,304 KB
testcase_07 AC 148 ms
86,116 KB
testcase_08 AC 213 ms
97,264 KB
testcase_09 AC 206 ms
99,796 KB
testcase_10 AC 113 ms
85,976 KB
testcase_11 AC 146 ms
82,416 KB
testcase_12 AC 134 ms
78,668 KB
testcase_13 AC 183 ms
102,292 KB
testcase_14 AC 165 ms
86,168 KB
testcase_15 AC 72 ms
71,276 KB
testcase_16 AC 71 ms
71,508 KB
testcase_17 AC 73 ms
71,624 KB
testcase_18 AC 74 ms
71,228 KB
testcase_19 AC 77 ms
75,064 KB
testcase_20 AC 82 ms
75,996 KB
testcase_21 AC 79 ms
75,780 KB
testcase_22 AC 78 ms
75,480 KB
testcase_23 AC 72 ms
71,520 KB
testcase_24 AC 72 ms
71,400 KB
testcase_25 AC 72 ms
71,384 KB
testcase_26 AC 72 ms
71,256 KB
testcase_27 AC 72 ms
71,352 KB
testcase_28 AC 113 ms
97,264 KB
testcase_29 AC 106 ms
92,516 KB
testcase_30 AC 92 ms
84,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

N,K=map(int,input().split())
A=["*"]+list(map(int,input().split()))

Ans=0
Q=[]; Q_sum=0
for i in range(N,0,-1):
    a=A[i]

    heappush(Q,a); Q_sum+=a

    if len(Q)>K-1:
        b=heappop(Q); Q_sum-=b
        if i%2==0:
            Ans=max(Ans,b+Q_sum)

print(Ans)
0