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>
using namespace std;
#define N 500005
#define sz size()
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define pt pop_back
ll a[N], b[N], c, l, k, tr, b1, c1, d, t, n, h;
string s, g;
int main() {
ios::sync_with_stdio(false);cin.tie(0);
cin >> n >> k;
c = n - k;
h += n;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++){
if(i + 1 <= n){
l ++;
b[l] = a[i + 1] - a[i] - 1;
}
}
sort(b + 1, b + l + 1);
// for(int i = 1; i <= l; i++)cout << b[i] << ' ';
// return 0;
for(int i = 1; i <= c; i++){
h += b[i];
}
cout << h<< '\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... |