結果

問題 No.2028 Even Choice
ユーザー hir355hir355
提出日時 2022-08-05 22:04:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 280 ms / 2,000 ms
コード長 369 bytes
コンパイル時間 847 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 118,268 KB
最終ジャッジ日時 2023-10-13 23:04:52
合計ジャッジ時間 6,634 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 271 ms
106,412 KB
testcase_01 AC 251 ms
106,936 KB
testcase_02 AC 280 ms
106,536 KB
testcase_03 AC 142 ms
116,680 KB
testcase_04 AC 167 ms
118,268 KB
testcase_05 AC 160 ms
82,092 KB
testcase_06 AC 259 ms
101,488 KB
testcase_07 AC 172 ms
83,828 KB
testcase_08 AC 232 ms
95,988 KB
testcase_09 AC 225 ms
95,508 KB
testcase_10 AC 113 ms
84,436 KB
testcase_11 AC 177 ms
81,340 KB
testcase_12 AC 163 ms
78,504 KB
testcase_13 AC 185 ms
97,532 KB
testcase_14 AC 192 ms
84,216 KB
testcase_15 AC 75 ms
71,136 KB
testcase_16 AC 77 ms
71,428 KB
testcase_17 AC 77 ms
71,220 KB
testcase_18 AC 77 ms
71,112 KB
testcase_19 AC 79 ms
75,212 KB
testcase_20 AC 85 ms
75,708 KB
testcase_21 AC 86 ms
75,284 KB
testcase_22 AC 80 ms
75,180 KB
testcase_23 AC 76 ms
71,424 KB
testcase_24 AC 74 ms
71,376 KB
testcase_25 AC 76 ms
71,120 KB
testcase_26 AC 77 ms
71,328 KB
testcase_27 AC 76 ms
71,244 KB
testcase_28 AC 115 ms
95,768 KB
testcase_29 AC 108 ms
89,356 KB
testcase_30 AC 98 ms
83,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
hq = []
for i in range(n - k + 1, n):
    ans += a[i]
    heapq.heappush(hq, a[i])
res = 0
for i in range(n - k, -1, -1):
    if i % 2:
        if res < ans + a[i]:
            res = ans + a[i]
    ans += a[i]
    heapq.heappush(hq, a[i])
    ans -= heapq.heappop(hq)
print(res)
0