Submission #972202

#TimeUsernameProblemLanguageResultExecution timeMemory
972202vjudge1Stove (JOI18_stove)C++17
100 / 100
22 ms2908 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define pon ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  int T=1;
#define ponchik signed main
#define pb push_back
#define pf push_front
#define endl "\n"
#define F first
#define S second

const int N=1e5+69,INF=1e18+1488;
int cnt[N];
map<pair<int,int>,int>mp;
void solve() {
	int n,k;
	cin>>n>>k;
	int a[n+7],m=n-k;
	for (int i=0; i<n; i++) cin>>a[i];
	sort(a,a+n);
	int s[n];
	for (int i=0; i<n-1; i++) s[i]=a[i+1]-a[i];
	sort(s,s+n-1);
	int sum=k;
	for (int i=0; i<m; i++) sum+=s[i];
	cout<<sum;
}

ponchik (/*Alfar ABI*/ ) {
    pon
//  freopen( "###.in" ,"r",stdin); freopen( "###.out" ,"w",stdout);
//	cin>>T;
	while (T--){solve();}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...