結果

問題 No.2548 Problem Selection
ユーザー rlangevinrlangevin
提出日時 2024-02-29 12:17:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 380 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 92,884 KB
最終ジャッジ日時 2024-02-29 12:17:41
合計ジャッジ時間 4,283 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
89,312 KB
testcase_01 AC 61 ms
72,600 KB
testcase_02 AC 106 ms
92,772 KB
testcase_03 AC 53 ms
68,576 KB
testcase_04 AC 83 ms
84,912 KB
testcase_05 AC 102 ms
92,860 KB
testcase_06 AC 58 ms
68,540 KB
testcase_07 AC 88 ms
86,712 KB
testcase_08 AC 107 ms
89,116 KB
testcase_09 AC 97 ms
89,936 KB
testcase_10 AC 101 ms
92,244 KB
testcase_11 AC 102 ms
92,884 KB
testcase_12 AC 97 ms
92,884 KB
testcase_13 AC 39 ms
53,460 KB
testcase_14 AC 39 ms
53,460 KB
testcase_15 AC 39 ms
53,460 KB
testcase_16 AC 39 ms
53,460 KB
testcase_17 AC 39 ms
53,460 KB
testcase_18 AC 39 ms
53,460 KB
testcase_19 AC 39 ms
53,460 KB
testcase_20 AC 39 ms
53,460 KB
testcase_21 AC 40 ms
53,460 KB
testcase_22 AC 40 ms
53,460 KB
testcase_23 AC 40 ms
53,460 KB
testcase_24 AC 41 ms
53,460 KB
testcase_25 AC 40 ms
53,460 KB
testcase_26 AC 39 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
Q = deque()
now = 0
for i in range(M):
    Q.append(A[i])
    if len(Q) >= 2:
        now += (Q[-1] - Q[-2])**2
ans = now
for i in range(M, N):
    Q.append(A[i])
    now += (Q[-1] - Q[-2]) ** 2
    now -= (Q[0] - Q[1]) ** 2
    Q.popleft()
    ans = min(ans, now)

print(ans)
0