結果

問題 No.1248 Kth Sum
ユーザー chineristACchineristAC
提出日時 2020-10-02 22:23:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 597 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 87,036 KB
実行使用メモリ 106,388 KB
最終ジャッジ日時 2023-09-24 21:22:31
合計ジャッジ時間 8,134 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
71,480 KB
testcase_01 AC 82 ms
71,372 KB
testcase_02 AC 84 ms
71,276 KB
testcase_03 AC 85 ms
71,432 KB
testcase_04 AC 84 ms
71,284 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 84 ms
71,484 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 135 ms
101,928 KB
testcase_14 WA -
testcase_15 AC 131 ms
102,224 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 83 ms
71,144 KB
testcase_24 WA -
testcase_25 AC 265 ms
106,388 KB
testcase_26 WA -
testcase_27 AC 133 ms
101,928 KB
testcase_28 AC 133 ms
102,036 KB
testcase_29 AC 134 ms
102,008 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush,heappop,heapify

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

if K==1:
    exit(print(A[0]))

ans = 10**18
que = []
S = 0
for i in range(1,N+1):
    if i*K>N:
        break
    tmp = 0
    if i!=1:
        t = A[(i-1)*K:i*K]
        t.sort(reverse=True)
        tmp += t.pop()
        while t and -que[0] > t[-1]:
            S += que[0]
            heappop(que)
            S += t[-1]
            heappush(que,-t.pop())
    else:
        tmp = A[i*K-1]
    tmp += S
    ans = min(ans,tmp)
    S += A[i*K-1]
    heappush(que,-A[i*K-1])

print(ans)
0