結果

問題 No.2028 Even Choice
ユーザー roarisroaris
提出日時 2022-08-06 07:37:24
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 400 bytes
コンパイル時間 391 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 116,992 KB
最終ジャッジ日時 2023-10-14 09:15:10
合計ジャッジ時間 7,070 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 246 ms
105,744 KB
testcase_01 AC 234 ms
105,992 KB
testcase_02 AC 240 ms
106,012 KB
testcase_03 AC 137 ms
116,992 KB
testcase_04 AC 138 ms
115,444 KB
testcase_05 AC 153 ms
82,068 KB
testcase_06 AC 228 ms
101,164 KB
testcase_07 AC 157 ms
83,488 KB
testcase_08 AC 188 ms
94,784 KB
testcase_09 AC 206 ms
95,472 KB
testcase_10 AC 111 ms
83,920 KB
testcase_11 AC 157 ms
81,124 KB
testcase_12 AC 144 ms
78,572 KB
testcase_13 AC 188 ms
97,880 KB
testcase_14 AC 168 ms
83,660 KB
testcase_15 AC 77 ms
71,532 KB
testcase_16 AC 77 ms
71,300 KB
testcase_17 AC 77 ms
71,028 KB
testcase_18 AC 77 ms
71,544 KB
testcase_19 AC 79 ms
71,352 KB
testcase_20 AC 86 ms
75,492 KB
testcase_21 AC 83 ms
75,652 KB
testcase_22 AC 81 ms
75,256 KB
testcase_23 RE -
testcase_24 AC 77 ms
71,472 KB
testcase_25 RE -
testcase_26 AC 77 ms
71,356 KB
testcase_27 AC 77 ms
71,044 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

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 pq[0]<A[i]:
        s -= heappop(pq)
        heappush(pq, A[i])
        s += A[i]

print(ans)
0