笑死了,除了一个毒瘤点以外最慢才210ms。。。。
// luogu-judger-enable-o2
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=100050;
int n,k;
inline void read(register int &x){
x=0; register char ch=getchar();
while(ch<'0'||ch>'9')ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
}
int main(){
read(n),read(k);
register int dp[2][maxn][2],a[maxn];
for(register int i=1;i<=n;i++)read(a[i]);
memset(dp,0x3f,sizeof(dp));
register int x=0;
dp[x][0][0]=0;
for(register int i=2;i<=n;i++){
x^=1;
dp[x][0][0]=dp[x^1][0][0];
for(register int j=max(k-((n-i+1)>>1),0);j<=min(k,(i>>1)+1);j++){
dp[x][j][0]=min(dp[x^1][j][0],dp[x^1][j][1]);
dp[x][j][1]=dp[x^1][j-1][0]+a[i]-a[i-1];
}
}
cout<<min(dp[x][k][0],dp[x][k][1])<<endl;
}