結果

問題 No.2028 Even Choice
ユーザー AkariAkari
提出日時 2022-08-05 22:03:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 523 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 39,424 KB
最終ジャッジ日時 2023-10-13 23:01:45
合計ジャッジ時間 9,771 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 261 ms
34,864 KB
testcase_01 AC 218 ms
36,796 KB
testcase_02 AC 239 ms
33,820 KB
testcase_03 AC 160 ms
39,424 KB
testcase_04 AC 164 ms
38,396 KB
testcase_05 AC 146 ms
31,332 KB
testcase_06 AC 229 ms
34,620 KB
testcase_07 AC 145 ms
31,916 KB
testcase_08 AC 196 ms
32,088 KB
testcase_09 AC 193 ms
34,516 KB
testcase_10 AC 140 ms
31,900 KB
testcase_11 AC 141 ms
30,544 KB
testcase_12 AC 127 ms
30,012 KB
testcase_13 AC 164 ms
36,888 KB
testcase_14 AC 149 ms
30,864 KB
testcase_15 AC 120 ms
29,572 KB
testcase_16 AC 121 ms
29,700 KB
testcase_17 AC 125 ms
29,780 KB
testcase_18 AC 125 ms
29,692 KB
testcase_19 AC 127 ms
29,688 KB
testcase_20 AC 129 ms
29,668 KB
testcase_21 AC 128 ms
29,732 KB
testcase_22 AC 130 ms
29,732 KB
testcase_23 AC 125 ms
29,684 KB
testcase_24 AC 125 ms
29,624 KB
testcase_25 AC 124 ms
29,536 KB
testcase_26 AC 122 ms
29,676 KB
testcase_27 AC 125 ms
29,704 KB
testcase_28 AC 138 ms
32,220 KB
testcase_29 AC 130 ms
31,876 KB
testcase_30 AC 125 ms
31,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from heapq import heappushpop, heappush
import numpy as np






def main():
    n, k = map(int, input().split())
    A = np.fromstring(input(), np.int64, sep=' ')
    if k == 1:
        print(A[1::2].max())
        exit()
    s = A[-k+1:].sum()
    q = []
    ans = s
    for a in A[-k+1:]: heappush(q, a)
    for i in range(n - k, -1, -1):
        a = A[i]
        if i & 1 and a + s > ans: ans = a + s
        s += a
        s -= heappushpop(q, a)
    print(ans)









if __name__ == '__main__':
    main()
0