Submission #151771

#TimeUsernameProblemLanguageResultExecution timeMemory
151771jhwest2Stove (JOI18_stove)C++14
100 / 100
33 ms2424 KiB
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int n, k;
int ans = 0;
int arr[101010];
priority_queue<int, vector<int>, greater<int>> pq;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);

	cin >> n >> k;
	for (int i=0; i<n; i++) cin >> arr[i];

	sort(arr, arr+n);

	for (int i=0; i<n-1; i++) {
		pq.push(arr[i+1]-arr[i]-1);
	}

	for (int i=0; i<n-k; i++) {
		ans += pq.top();
		pq.pop();
	}

	ans += n;

	cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...