結果

問題 No.2028 Even Choice
ユーザー SidewaysOwlSidewaysOwl
提出日時 2022-08-05 22:03:35
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 389 ms / 2,000 ms
コード長 444 bytes
コンパイル時間 559 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 162,252 KB
最終ジャッジ日時 2023-10-13 23:02:38
合計ジャッジ時間 7,977 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 385 ms
161,556 KB
testcase_01 AC 369 ms
162,252 KB
testcase_02 AC 389 ms
161,536 KB
testcase_03 AC 158 ms
114,064 KB
testcase_04 AC 181 ms
112,916 KB
testcase_05 AC 199 ms
91,152 KB
testcase_06 AC 370 ms
161,088 KB
testcase_07 AC 207 ms
95,980 KB
testcase_08 AC 311 ms
122,480 KB
testcase_09 AC 311 ms
128,056 KB
testcase_10 AC 157 ms
96,784 KB
testcase_11 AC 205 ms
88,064 KB
testcase_12 AC 177 ms
81,236 KB
testcase_13 AC 279 ms
133,440 KB
testcase_14 AC 231 ms
96,068 KB
testcase_15 AC 87 ms
71,832 KB
testcase_16 AC 87 ms
71,376 KB
testcase_17 AC 89 ms
71,632 KB
testcase_18 AC 92 ms
71,364 KB
testcase_19 AC 98 ms
76,428 KB
testcase_20 AC 101 ms
76,692 KB
testcase_21 AC 100 ms
76,452 KB
testcase_22 AC 97 ms
76,260 KB
testcase_23 AC 89 ms
71,656 KB
testcase_24 AC 88 ms
71,396 KB
testcase_25 AC 86 ms
71,788 KB
testcase_26 AC 89 ms
71,660 KB
testcase_27 AC 89 ms
71,676 KB
testcase_28 AC 193 ms
119,276 KB
testcase_29 AC 159 ms
106,480 KB
testcase_30 AC 137 ms
95,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
from collections import defaultdict
import heapq
d = defaultdict(int)
sum_ = 0
q = []
for i,e in enumerate(sorted(set(a))):
    d[e] = i + 1
for i in range(n-1,0,-1):
    if i & 1:
        ans = max(ans ,a[i] + sum_)
        heapq.heappush(q,a[i])
    else:
        heapq.heappush(q,a[i])
    sum_ += a[i]
    if len(q) > k-1:
        sum_ -= heapq.heappop(q)
print(ans)
0