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>
#define N 100005
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int n, k, v[N];
vector<ll> vet;
int main()
{
cin>>n>>k;
for(int i = 1; i <= n; i++) cin>>v[i];
sort(v + 1, v + n + 1);
for(int i = 1; i < n; i++) vet.push_back(v[i] - v[i + 1]);
sort(vet.begin(), vet.end());
ll ans = v[n] - v[1] + k;
for(int i = 0; i < k - 1; i++) ans += vet[i];
cout<<ans<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |