結果

問題 No.2028 Even Choice
ユーザー FromBooskaFromBooska
提出日時 2024-03-18 16:43:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 743 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 113,932 KB
最終ジャッジ日時 2024-03-18 16:43:11
合計ジャッジ時間 5,992 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 201 ms
102,564 KB
testcase_01 AC 182 ms
102,564 KB
testcase_02 AC 218 ms
102,568 KB
testcase_03 AC 112 ms
113,932 KB
testcase_04 AC 131 ms
112,520 KB
testcase_05 AC 104 ms
81,244 KB
testcase_06 AC 187 ms
104,976 KB
testcase_07 AC 109 ms
83,276 KB
testcase_08 AC 167 ms
96,072 KB
testcase_09 AC 156 ms
98,992 KB
testcase_10 AC 82 ms
83,268 KB
testcase_11 AC 109 ms
79,988 KB
testcase_12 AC 101 ms
76,832 KB
testcase_13 AC 136 ms
102,232 KB
testcase_14 AC 126 ms
83,356 KB
testcase_15 AC 35 ms
53,460 KB
testcase_16 AC 36 ms
53,460 KB
testcase_17 AC 35 ms
53,460 KB
testcase_18 AC 38 ms
53,460 KB
testcase_19 AC 40 ms
59,072 KB
testcase_20 AC 47 ms
61,716 KB
testcase_21 AC 46 ms
61,332 KB
testcase_22 AC 42 ms
59,068 KB
testcase_23 AC 36 ms
53,460 KB
testcase_24 AC 37 ms
53,460 KB
testcase_25 AC 36 ms
53,460 KB
testcase_26 AC 36 ms
53,460 KB
testcase_27 AC 35 ms
53,460 KB
testcase_28 AC 80 ms
93,888 KB
testcase_29 AC 66 ms
84,036 KB
testcase_30 AC 58 ms
76,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 取れるのは偶数番だけ、最初に偶数番を取れば、あとは奇数番が偶数番になるので結局好きなのを取れる
# つまり最初だけ偶数番、あとは好きなのを取れる
# 逆順heapでK-1個の最高値を事前計算するか

from heapq import heapify, heappop, heappush

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


largest_sum = [0]*N
H = []
heapify(H)
s = 0
for i in range(N-1, 0, -1):
    heappush(H, A[i])
    s += A[i]
    if len(H)>K-1:
        smallest = heappop(H)
        s -= smallest
    largest_sum[i-1] = s

#print(A)
#print(largest_sum)

ans = 0
for i in range(N):
    if i%2 == 1:
        calc = A[i]+largest_sum[i]
        ans = max(ans, calc)
print(ans)
0