1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<queue>
 7 using namespace std;
 8 #define Maxn 100100
 9 
10 struct node
11 {
12     int id,x;
13     friend bool operator < (node x,node y)
14     {
15         return x.x>y.x;
16     }
17 };
18 
19 priority_queue<node > q;
20 
21 int a[2*Maxn],lt[2*Maxn],nt[2*Maxn];
22 bool mark[2*Maxn];
23 
24 int main()
25 {
26     int n,k;
27     scanf("%d%d",&n,&k);
28     int now,nw;
29     scanf("%d",&now);
30     for(int i=2;i<=n;i++)
31     {
32         scanf("%d",&nw);
33         a[i-1]=nw-now;
34         now=nw;
35     }
36     n--;
37     while(!q.empty()) q.pop();
38     for(int i=1;i<=n;i++) nt[i]=i+1;nt[n]=-1;
39     for(int i=1;i<=n;i++) lt[i]=i-1;
40     for(int i=1;i<=n;i++)
41     {
42         node xx;
43         xx.id=i;xx.x=a[i];
44         q.push(xx);
45     }
46     memset(mark,0,sizeof(mark));
47     int ans=0,cnt=n;
48     for(int i=1;i<=k;i++)
49     {
50         while(mark[q.top().id]) q.pop();
51         node xx;
52         xx=q.top();q.pop();
53         ans+=xx.x;
54         if(lt[xx.id]==0)
55         {
56             mark[nt[xx.id]]=1;
57             lt[nt[nt[xx.id]]]=0;
58         }
59         else if(nt[xx.id]==-1)
60         {
61             mark[lt[xx.id]]=1;
62             nt[lt[lt[xx.id]]]=-1;
63         }
64         else
65         {
66             mark[nt[xx.id]]=1;
67             mark[lt[xx.id]]=1;
68             cnt++;
69             nt[lt[lt[xx.id]]]=cnt;
70             lt[nt[nt[xx.id]]]=cnt;
71             lt[cnt]=lt[lt[xx.id]];
72             nt[cnt]=nt[nt[xx.id]];
73             node nw;
74             nw.id=cnt;
75             nw.x=a[lt[xx.id]]+a[nt[xx.id]]-xx.x;
76             a[cnt]=nw.x;
77             q.push(nw);
78         }
79     }
80     printf("%d\n",ans);
81     return 0;
82 }