package main import . "fmt" import . "os" import bf "bufio" import . "slices" func main() { rd:=bf.NewReader(Stdin) var n,m int Fscan(rd,&n,&m) a:=make([]int64,n) for i:=range a { Fscan(rd,&a[i]) } Sort(a) var x,y int var ans,s int64 for { if x-y+1 < m { x++ if x>=n { break } s+=(a[x]-a[x-1])*(a[x]-a[x-1]) } else { if ans==0||s=n { break } s-=(a[y]-a[y-1])*(a[y]-a[y-1]) } } Println(ans) }