#include <cstdio> #include <algorithm> int a[2001]; int dp[2001][1001]={0}; using namespace std; int main() { int n,k,i=1,j=1; while(scanf("%d %d",&n,&k)==2){ for(i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1); for(i=2;i<=n;i++) for(j=1;j<=i/2;j++){ if(i==j*2) dp[i][j]=dp[i-2][j-1]+(a[i]-a[i-1])*(a[i]-a[i-1]); if(i>2*j) dp[i][j]=min(dp[i-1][j],dp[i-2][j-1]+(a[i]-a[i-1])*(a[i]-a[i-1])); } printf("%d ",dp[n][k]);} return 0; }