import java.util.*; import java.math.BigInteger; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); int M = in.nextInt(); int[] A = new int[N]; for (int i = 0; i < N; i++) A[i] = in.nextInt(); Arrays.sort(A); BigInteger L = BigInteger.valueOf(Long.MAX_VALUE); BigInteger curL = BigInteger.valueOf(0); //初始化第一个区间 int l = 0; int r = M - 1; for (int i = l; i < r; i++) { curL = curL.add(sq(A[i + 1]).subtract(sq(A[i]))); } if (L.compareTo(curL) > 0) L = curL; //遍历剩余区间 for (l = 1; l <= N - M; l++) { //移除l-1与l的差 //新增l+M-1与l+M-2的差 curL = curL .subtract(sq(A[l]).subtract(sq(A[l - 1]))); curL = curL .add (sq(A[l + M - 1]).subtract(sq(A[l + M - 2]))); if (L.compareTo(curL) > 0) L = curL; } System.out.println(L); } private static BigInteger sq(long num) { BigInteger res = BigInteger.valueOf(num); return res.multiply(res); } }