This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(long long (i)=0;(i)<(n);++(i))
//REF TE KUCUK ESITTIR YOK DIKKKKKKKKKKKKATTTTTT
#define ref(i,a,b) for (long long (i)=(a); (i)<(b); ++(i))
#define INF 0xFFFFFF
#define endl '\n'
#define pb push_back
#define mp make_pair
const unsigned int mod = 1e9+7;
const int mx=1e5+5;
int n,k;//ll or int ?
ll ans=1e17;
ll a[mx];
ll sub[mx-1];
/*void solve(ll v,ll kk,ll bitti,ll top){
	if(v==(n-1) and kk==(k-1)){
	//	if(bitti)
			ans=min(ans,top+1);
	//	else return;
	}
	else if(v==(n-1) and kk==k){
		if(!bitti)
			ans=min(ans,top);
		else return;
	}
	if(v==(n-1))return;
	if(kk>k)return;
	if(bitti){
		solve(v+1,kk+1,bitti,top+1);
		solve(v+1,kk,1-bitti,top+sub[v]+1);
	}
	else{
		solve(v+1,kk,bitti,top+sub[v]);//dikkat
		solve(v+1,kk+1,1-bitti,top+1);
	}
	return;
}*/
int main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout); 
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin >> n >> k;
	rep(i,n)cin >> a[i];
	ll ans=n;
	int cc=0;
	vector <int> wait;
	ref(i,1,n){
		if(!(a[i]==(a[i-1]+1))){
			wait.pb(a[i]-a[i-1]-1);
			++cc;
		}
	}
	++cc;
	sort(wait.begin(),wait.end());
	rep(i,wait.size())cout << wait[i] << " ";
	cout << endl;
	for(int i=0;i<max(0,cc-k);++i)ans+=wait[i];
	cout << ans << endl;
}
	
Compilation message (stderr)
stove.cpp: In function 'int main()':
stove.cpp:4:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i,n) for(long long (i)=0;(i)<(n);++(i))
                                      ~~~^~~~
stove.cpp:58:2: note: in expansion of macro 'rep'
  rep(i,wait.size())cout << wait[i] << " ";
  ^~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |