結果

問題 No.2548 Problem Selection
ユーザー 👑 KA37RIKA37RI
提出日時 2023-11-25 16:11:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 248 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 21,188 KB
最終ジャッジ日時 2023-11-25 16:11:09
合計ジャッジ時間 3,368 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 103 ms
18,064 KB
testcase_01 AC 60 ms
12,832 KB
testcase_02 AC 172 ms
20,592 KB
testcase_03 AC 46 ms
11,264 KB
testcase_04 AC 115 ms
16,476 KB
testcase_05 AC 145 ms
20,628 KB
testcase_06 AC 46 ms
11,392 KB
testcase_07 AC 142 ms
17,824 KB
testcase_08 AC 140 ms
18,932 KB
testcase_09 AC 166 ms
19,236 KB
testcase_10 AC 190 ms
21,188 KB
testcase_11 AC 158 ms
21,188 KB
testcase_12 AC 137 ms
21,188 KB
testcase_13 AC 30 ms
9,984 KB
testcase_14 AC 30 ms
9,984 KB
testcase_15 AC 29 ms
9,984 KB
testcase_16 AC 30 ms
9,984 KB
testcase_17 AC 29 ms
9,984 KB
testcase_18 AC 29 ms
9,984 KB
testcase_19 AC 30 ms
9,984 KB
testcase_20 AC 29 ms
9,984 KB
testcase_21 AC 30 ms
9,984 KB
testcase_22 AC 30 ms
9,984 KB
testcase_23 AC 31 ms
9,984 KB
testcase_24 AC 30 ms
9,984 KB
testcase_25 AC 29 ms
9,984 KB
testcase_26 AC 30 ms
9,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
d = []
for i in range(1, n):
	d.append((a[i] - a[i-1]) ** 2)
s = sum(d[:m-1])
ans = s
for i in range(n - m):
	s += d[i+m-1] - d[i]
	ans = min(s, ans)
print(ans)
0