結果

問題 No.2028 Even Choice
ユーザー FromBooskaFromBooska
提出日時 2023-08-09 18:55:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 781 bytes
コンパイル時間 201 ms
コンパイル使用メモリ 81,948 KB
実行使用メモリ 112,208 KB
最終ジャッジ日時 2024-04-27 13:38:03
合計ジャッジ時間 5,472 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 218 ms
101,964 KB
testcase_01 AC 192 ms
101,844 KB
testcase_02 AC 225 ms
101,692 KB
testcase_03 WA -
testcase_04 AC 131 ms
110,812 KB
testcase_05 AC 113 ms
80,828 KB
testcase_06 AC 197 ms
103,696 KB
testcase_07 AC 117 ms
82,968 KB
testcase_08 AC 181 ms
95,232 KB
testcase_09 AC 166 ms
97,988 KB
testcase_10 AC 80 ms
82,736 KB
testcase_11 AC 119 ms
79,772 KB
testcase_12 AC 107 ms
77,496 KB
testcase_13 AC 139 ms
101,204 KB
testcase_14 AC 135 ms
83,048 KB
testcase_15 AC 40 ms
52,916 KB
testcase_16 AC 39 ms
53,408 KB
testcase_17 AC 39 ms
53,468 KB
testcase_18 AC 43 ms
53,228 KB
testcase_19 AC 45 ms
59,020 KB
testcase_20 AC 51 ms
63,124 KB
testcase_21 AC 49 ms
60,244 KB
testcase_22 AC 46 ms
59,768 KB
testcase_23 AC 40 ms
53,624 KB
testcase_24 AC 40 ms
53,776 KB
testcase_25 AC 39 ms
52,244 KB
testcase_26 WA -
testcase_27 AC 39 ms
53,408 KB
testcase_28 AC 77 ms
93,344 KB
testcase_29 AC 68 ms
83,364 KB
testcase_30 AC 62 ms
75,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 一番手前の数字は偶数番目である必要ある
# それ以後で元々偶数番なら最初にとればいいので取れる
# それ以後で奇数番なら最初の偶数番を取ってから取ればいいので取れる
# つまり一番手前が偶数番ならば自由にとれる
# 後ろからheapで高いものを管理
# 偶数番をとったときにans更新

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

from heapq import *
H = []
heapify(H)
s = 0
ans = 0
for i in range(N-1, -1, -1):
    a = A[i]
    if len(H) < K:
        heappush(H, a)
        s += a
    else:
        smallest = heappop(H)
        heappush(H, a)
        s -= smallest
        s += a
        if i%2 == 1: 
            ans = max(ans, s)
    
print(ans)






0