結果

問題 No.2028 Even Choice
ユーザー roarisroaris
提出日時 2022-08-06 07:39:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 221 ms / 2,000 ms
コード長 414 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 116,932 KB
最終ジャッジ日時 2023-10-14 09:16:15
合計ジャッジ時間 5,892 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 221 ms
105,896 KB
testcase_01 AC 203 ms
106,100 KB
testcase_02 AC 208 ms
106,124 KB
testcase_03 AC 125 ms
116,932 KB
testcase_04 AC 125 ms
115,668 KB
testcase_05 AC 133 ms
82,148 KB
testcase_06 AC 204 ms
101,340 KB
testcase_07 AC 134 ms
83,836 KB
testcase_08 AC 184 ms
94,804 KB
testcase_09 AC 188 ms
95,440 KB
testcase_10 AC 95 ms
83,928 KB
testcase_11 AC 139 ms
81,180 KB
testcase_12 AC 123 ms
78,524 KB
testcase_13 AC 165 ms
97,780 KB
testcase_14 AC 145 ms
83,976 KB
testcase_15 AC 66 ms
71,428 KB
testcase_16 AC 68 ms
71,476 KB
testcase_17 AC 64 ms
71,548 KB
testcase_18 AC 63 ms
71,380 KB
testcase_19 AC 63 ms
71,168 KB
testcase_20 AC 75 ms
75,644 KB
testcase_21 AC 69 ms
75,380 KB
testcase_22 AC 65 ms
75,372 KB
testcase_23 AC 62 ms
71,348 KB
testcase_24 AC 62 ms
71,148 KB
testcase_25 AC 64 ms
71,464 KB
testcase_26 AC 66 ms
71,484 KB
testcase_27 AC 66 ms
71,544 KB
testcase_28 AC 93 ms
95,096 KB
testcase_29 AC 85 ms
88,672 KB
testcase_30 AC 83 ms
83,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from heapq import *

N, K = map(int, input().split())
A = list(map(int, input().split()))
pq = []
s = 0

for i in range(N-1, N-K, -1):
    heappush(pq, A[i])
    s += A[i]

ans = 0

for i in range(N-K, -1, -1):
    if i%2==1:
        ans = max(ans, A[i]+s)
    
    if len(pq)>0 and pq[0]<A[i]:
        s -= heappop(pq)
        heappush(pq, A[i])
        s += A[i]

print(ans)
0