結果
| 問題 |
No.1248 Kth Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-02 22:23:36 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 597 bytes |
| コンパイル時間 | 151 ms |
| コンパイル使用メモリ | 82,136 KB |
| 実行使用メモリ | 106,796 KB |
| 最終ジャッジ日時 | 2024-07-17 21:48:10 |
| 合計ジャッジ時間 | 6,062 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 11 WA * 25 |
ソースコード
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)