using System.Collections; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; internal class Program { private const long mod = 998244353; private const long mod17 = 1000000007; private const long INF = mod17 * mod17; public static void Main(string[] args) { var line = getar(); int n = line[0], m = line[1]; var a = getar(); Array.Sort(a); List rd = mkar(n, (long)0); for (int i = 0; i + 1 < n; i++) { long dif = a[i + 1] - a[i]; rd[i + 1] = rd[i] + dif * dif; } long ans = INF; for (int i = 0; i < n - (m - 1); i++) { long val = rd[i + m - 1] - rd[i]; ans = Math.Min(ans, val); } Console.WriteLine(ans); } public class lower_bound : IComparer where T : IComparable { public int Compare(T x, T y) { return 0 <= x.CompareTo(y) ? 1 : -1; } } public static List mkar(int n, T val) { List res = new List(n); for(int i=0;i