Submission #1241884

#TimeUsernameProblemLanguageResultExecution timeMemory
1241884nguyenphong233Stove (JOI18_stove)C++20
100 / 100
11 ms1224 KiB
// 23 - 12 - 23 

#include<bits/stdc++.h>

using namespace std;

#define read() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define day() time_t now = time(0);char* x = ctime(&now);cerr<<"Right Now Is : "<<x<<"\n"

#define ii pair<int,int>
#define X first
#define Y second 

const long long MAX = (int)1e5 + 5;
const long long INF = (int)1e9;
const long long MOD = (int)1e9 + 7;

int n,k;
int a[MAX];

signed main(){
	
	read();
	
	cin >> n >> k;
	vector<int> rt;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
		if(i > 1)rt.push_back(a[i] - a[i - 1] - 1);
	}	
	int ans = n;
	sort(rt.begin(),rt.end());
	for(int i = 0;i < n - k;i++)ans += rt[i];
	cout << ans;
	
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...