제출 #753971

#제출 시각아이디문제언어결과실행 시간메모리
753971ZeroCoolStove (JOI18_stove)C++17
100 / 100
25 ms2244 KiB
//*--- ©ZeroCoolCorp --- *//

#include <bits/stdc++.h>
#define endl '\n'
#define debug(v) cerr<<v<<endl;


#define ll long long
#define ld long double

using namespace std;

const int mxn = 2e5 + 5;
const int LOG = 20;
const int mod = 1e9 + 7;
const int inf = 1e9;


void solve(int T){
	priority_queue<int,vector<int>,greater<int>>q;
	int n,k;
	cin>>n>>k;
	int a[n];
	
	for(int i = 0;i < n;i++){
		cin>>a[i];
		if(i > 0)q.push(a[i] - a[i - 1]);
	}
	
	ll ans = n;
	k = n - k;
	while(k > 0){
		ans += q.top();
		ans--;
		q.pop();
		k--;
	}
	cout<<ans<<endl;
}



int main() {
    
	ios::sync_with_stdio(false);
    cin.tie(NULL);
   

    int t = 1;
//    cin>>t;
    for(int i = 1;i<=t;i++)solve(i);
}

//*--- This is code from the best programer ---*//
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...