結果

問題 No.2028 Even Choice
ユーザー wattaiheiwattaihei
提出日時 2022-08-05 22:38:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 362 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 118,832 KB
最終ジャッジ日時 2023-10-14 00:05:50
合計ジャッジ時間 6,609 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 275 ms
105,728 KB
testcase_01 AC 255 ms
106,056 KB
testcase_02 AC 285 ms
105,896 KB
testcase_03 AC 150 ms
116,772 KB
testcase_04 AC 179 ms
118,832 KB
testcase_05 AC 178 ms
82,464 KB
testcase_06 AC 269 ms
100,388 KB
testcase_07 AC 174 ms
84,340 KB
testcase_08 AC 240 ms
95,436 KB
testcase_09 AC 231 ms
94,552 KB
testcase_10 AC 127 ms
84,164 KB
testcase_11 AC 179 ms
81,344 KB
testcase_12 AC 161 ms
78,608 KB
testcase_13 AC 195 ms
96,640 KB
testcase_14 AC 197 ms
84,188 KB
testcase_15 AC 77 ms
71,156 KB
testcase_16 AC 77 ms
71,340 KB
testcase_17 AC 76 ms
71,276 KB
testcase_18 AC 81 ms
71,452 KB
testcase_19 AC 83 ms
74,856 KB
testcase_20 AC 90 ms
75,740 KB
testcase_21 AC 87 ms
75,504 KB
testcase_22 AC 84 ms
75,380 KB
testcase_23 AC 78 ms
71,260 KB
testcase_24 AC 77 ms
71,340 KB
testcase_25 AC 77 ms
71,064 KB
testcase_26 AC 78 ms
71,384 KB
testcase_27 AC 78 ms
71,328 KB
testcase_28 AC 118 ms
95,408 KB
testcase_29 AC 111 ms
89,972 KB
testcase_30 AC 102 ms
83,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from heapq import heappop, heappush

N, K = map(int, input().rstrip().split())
A = list(map(int, input().rstrip().split()))

q = []
qs = 0
ans = 0
for i in reversed(range(N)):
    a = A[i]
    if i%2 == 1:
        ans = max(ans, qs + a)
    heappush(q, a)
    qs += a
    if len(q) >= K:
        qs -= heappop(q)

print(ans)
0