//P3620 [APIO/CTSC 2007] 数据备份
//把每组相邻城市的距离作为点 则题意转化为n-1中选取k个点
//使总和最小且这些点互不相邻;反悔策略:用选取的点相邻两点之和减去该点点权作为返回策略
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f
const int nn=500010;
inline ll read(){
ll w=1,s=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-1')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return w*s;
}
struct node{
ll v,id;
bool operator < (const node &xs) const{
return v>xs.v;
}
}t,s,f;
struct nd{
ll v,l,r;
}p[nn];
inline void del(int x)
{
p[x].l=p[p[x].l].l;
p[x].r=p[p[x].r].r;
p[p[x].l].r=x;
p[p[x].r].l=x;
}
ll k,qwq,n,m,l,qaq;
bool vis[nn];
priority_queue<node> q;
void init(node a){cout<<a.id<<" "<<a.v<<endl;}
int main(){
n=read();m=read();l=read();
for(int i=1;i<n;i++){
qwq=read();
p[i].v=qwq-l;l=qwq;
p[i].l=i-1;p[i].r=i+1;
s.id=i;s.v=p[i].v;
q.push(s);
// cout<<s.id<<" ";
}
p[0].v=p[n].v=inf;
for(int i=1;i<=m;++i){
while(vis[q.top().id])
q.pop();
t=q.top();q.pop();
qaq+=t.v;
vis[p[t.id].l]=vis[p[t.id].r]=1;
p[t.id].v=p[p[t.id].l].v+p[p[t.id].r].v-p[t.id].v;
f.v=p[t.id].v;f.id=t.id;
q.push(f);
// init(t);
del(f.id);
// cout<<t.id<<" "<<t.v<<endl;
}
cout<<qaq;
return 0;
}
输出203998411 正解537092323 不太理解哪里错了求大佬指教