結果

問題 No.615 集合に分けよう
ユーザー flippergo
提出日時 2024-12-09 22:39:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 333 bytes
コンパイル時間 373 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 76,672 KB
最終ジャッジ日時 2024-12-09 22:39:04
合計ジャッジ時間 3,783 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 14 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))
ans = sum(A)
if K==1:
    ans = A[N-1]-A[0]
elif K==2:
    for i in range(1,N):
        cnt = A[i-1]-A[0]+A[N-1]-A[i]
        ans = min(ans,cnt)
else:
    for i in range(1,N-K+2):
        cnt = A[i-1]-A[0]+A[N-1]-A[i+K-2]
        ans = min(ans,cnt)
print(ans)
0