結果

問題 No.2028 Even Choice
ユーザー ntudantuda
提出日時 2022-10-08 12:12:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 590 bytes
コンパイル時間 1,073 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 107,900 KB
最終ジャッジ日時 2023-09-04 15:11:32
合計ジャッジ時間 8,711 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 280 ms
106,432 KB
testcase_01 WA -
testcase_02 AC 279 ms
106,344 KB
testcase_03 AC 152 ms
107,576 KB
testcase_04 AC 170 ms
107,900 KB
testcase_05 AC 170 ms
82,264 KB
testcase_06 AC 265 ms
100,684 KB
testcase_07 AC 172 ms
84,552 KB
testcase_08 AC 224 ms
95,928 KB
testcase_09 AC 226 ms
94,600 KB
testcase_10 WA -
testcase_11 AC 174 ms
81,720 KB
testcase_12 AC 150 ms
78,788 KB
testcase_13 WA -
testcase_14 AC 191 ms
84,388 KB
testcase_15 AC 78 ms
71,288 KB
testcase_16 AC 79 ms
71,404 KB
testcase_17 AC 79 ms
71,332 KB
testcase_18 AC 80 ms
71,328 KB
testcase_19 AC 82 ms
71,316 KB
testcase_20 AC 92 ms
75,872 KB
testcase_21 AC 85 ms
75,444 KB
testcase_22 WA -
testcase_23 AC 78 ms
71,476 KB
testcase_24 AC 79 ms
71,348 KB
testcase_25 AC 77 ms
71,288 KB
testcase_26 WA -
testcase_27 AC 79 ms
71,292 KB
testcase_28 AC 108 ms
96,128 KB
testcase_29 AC 98 ms
89,132 KB
testcase_30 AC 94 ms
83,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
N, K = map(int, input().split())
A = list(map(int, input().split()))
K2 = (K - 1) // 2 * 2 + 2 - (K & 1)
X = A[N - K2:N]
if K == 1:
    print(max(A[1:N:2]))
    exit()
heapq.heapify(X)
while len(X) > K - 1:
    heapq.heappop(X)
tmp = sum(X)
ans = A[1] + tmp
for i in reversed(range(1, N - K2, 2)):
    ans = max(ans, A[i] + tmp)
    if i == 1:
        break
    for j in range(2):
        tmp2 = heapq.heappop(X)
        a = A[i - j]
        if tmp2 > a:
            heapq.heappush(X, tmp2)
        else:
            tmp += a - tmp2
            heapq.heappush(X, a)
print(ans)
0