#include <stdio.h> #include <string.DP(3)h>
#include <alDP(3)gorithm>
using namespace std; #define MAX 0x7fffffff #define M (2000 + 5) #define ___min(a,b) (a < b ? a : b) #define __pow(a) ((a) * (a)) int id[M],dp[M][M / 2]; void run() { int n,k; while(scanf("%d%d",&n,&k) != EOF) { for(int i=1; i<=n; i++) { scanf("%d",id + i); } sort(id + 1,id + n + 1); memset(dp,0,sizeof(dp)); for(i=2; i<=n; i++) { for(int j=1; j<=i/2; j++) { if(i == 2*j) dp[i][j] = dp[i - 2][j - 1] + __pow(id[i] - id[i -1]); else dp[i][j] = ___min(dp[i - 1][j],dp[i - 2][j - 1] + __pow(id[i] - id[i - 1])); } } printf("%d ",dp[n][k]); } } int main(int argc, char* argv[]) { #ifdef __MYLOCAL freopen("in.txt","r",stdin); #endif run(); return 0; }