結果

問題 No.2028 Even Choice
ユーザー ntudantuda
提出日時 2022-10-08 12:41:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 691 bytes
コンパイル時間 1,273 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 107,932 KB
最終ジャッジ日時 2023-09-04 16:05:44
合計ジャッジ時間 7,681 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 285 ms
106,188 KB
testcase_01 AC 259 ms
106,548 KB
testcase_02 AC 288 ms
106,060 KB
testcase_03 AC 156 ms
107,600 KB
testcase_04 AC 177 ms
107,932 KB
testcase_05 AC 173 ms
82,212 KB
testcase_06 AC 269 ms
100,336 KB
testcase_07 AC 172 ms
84,324 KB
testcase_08 AC 227 ms
95,424 KB
testcase_09 AC 231 ms
94,532 KB
testcase_10 AC 130 ms
84,352 KB
testcase_11 AC 170 ms
81,472 KB
testcase_12 AC 146 ms
78,280 KB
testcase_13 AC 196 ms
96,720 KB
testcase_14 AC 190 ms
84,048 KB
testcase_15 AC 76 ms
71,228 KB
testcase_16 AC 77 ms
71,260 KB
testcase_17 AC 77 ms
71,180 KB
testcase_18 AC 79 ms
71,124 KB
testcase_19 AC 81 ms
71,132 KB
testcase_20 AC 88 ms
75,660 KB
testcase_21 AC 86 ms
75,312 KB
testcase_22 AC 83 ms
75,320 KB
testcase_23 AC 77 ms
71,464 KB
testcase_24 AC 77 ms
71,060 KB
testcase_25 AC 78 ms
71,060 KB
testcase_26 AC 77 ms
71,112 KB
testcase_27 AC 75 ms
71,168 KB
testcase_28 AC 108 ms
96,040 KB
testcase_29 AC 98 ms
88,784 KB
testcase_30 AC 92 ms
83,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

if K == 1:
    print(max(A[1:N:2]))
    exit()

# ある偶数より後の枚数(N-i(odd))でK-1より大きい数
if N & 1 :
    K2 = (K - 1) // 2 * 2 + 1
else:
    K2 = K // 2 * 2

X= A[N - K2:N]
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