結果

問題 No.2548 Problem Selection
ユーザー Nikkuniku029Nikkuniku029
提出日時 2023-11-25 13:17:58
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 387 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 21,820 KB
最終ジャッジ日時 2024-09-26 10:24:50
合計ジャッジ時間 3,706 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import pairwise
from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
C = []
for x, y in pairwise(A):
    C.append((y - x) ** 2)
q = deque()
ans = float("inf")
tmp = 0
for i in range(len(C)):
    q.append(C[i])
    tmp += C[i]
    if len(q) == M - 1:
        ans = min(ans, tmp)
        tmp -= q.popleft()
print(ans)
0