#include #include #define min(a,b) a=2*i) { select[j][i]=min(select[j-1][i],select[j-2][i-1]+(thing[j]-thing[j-1])*(thing[j]-thing[j-1])); } else select[j][i]=select[j-2][i-1]+(thing[j]-thing[j-1])*(thing[j]-thing[j-1]); } } printf("%d\n",select[n][k]); return 0; } int main() { while(scanf("%d%d",&n,&k)!=EOF&&n>=2*k&&n<2000&&k>=1) { for(int i=1;i<=n;i++) scanf("%d",&thing[i]); dp(); } return 0; }