結果

問題 No.2028 Even Choice
ユーザー 👑 H20H20
提出日時 2022-08-05 21:49:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 375 bytes
コンパイル時間 380 ms
コンパイル使用メモリ 86,812 KB
実行使用メモリ 118,108 KB
最終ジャッジ日時 2023-10-13 22:31:42
合計ジャッジ時間 6,714 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 278 ms
106,352 KB
testcase_01 AC 255 ms
106,360 KB
testcase_02 AC 278 ms
106,572 KB
testcase_03 AC 145 ms
116,968 KB
testcase_04 AC 169 ms
118,108 KB
testcase_05 AC 171 ms
82,116 KB
testcase_06 AC 270 ms
101,320 KB
testcase_07 AC 172 ms
84,204 KB
testcase_08 AC 240 ms
95,324 KB
testcase_09 AC 238 ms
95,260 KB
testcase_10 AC 121 ms
84,356 KB
testcase_11 AC 176 ms
81,164 KB
testcase_12 AC 167 ms
78,252 KB
testcase_13 AC 192 ms
97,296 KB
testcase_14 AC 200 ms
84,156 KB
testcase_15 AC 79 ms
70,992 KB
testcase_16 AC 79 ms
71,168 KB
testcase_17 AC 76 ms
71,288 KB
testcase_18 AC 81 ms
71,288 KB
testcase_19 AC 82 ms
75,296 KB
testcase_20 AC 89 ms
75,776 KB
testcase_21 AC 86 ms
75,364 KB
testcase_22 AC 86 ms
75,396 KB
testcase_23 AC 79 ms
71,188 KB
testcase_24 AC 80 ms
70,996 KB
testcase_25 AC 81 ms
70,944 KB
testcase_26 AC 79 ms
71,124 KB
testcase_27 AC 78 ms
71,156 KB
testcase_28 AC 122 ms
95,536 KB
testcase_29 AC 112 ms
89,648 KB
testcase_30 AC 103 ms
83,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
N,K = map(int, input().split())
A = list(map(int, input().split()))
H = []
heapSum = 0
ans = 0
for i in reversed(range(N)):
    if len(H)<K-1:
        heapq.heappush(H,A[i])
        heapSum+=A[i]
    else:
        if i%2==1:
            ans = max(ans,A[i]+heapSum)
        heapSum+=A[i]
        heapq.heappush(H,A[i])
        heapSum-=heapq.heappop(H)
print(ans)
0