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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<long long int>d;
bool comp(long long int a,long long int b){
return a > b;
}
int main() {
long long int n, k;
long long int sumd;
cin >> n >> k;
long long int a;
cin >> a;
sumd = a;
long long int b;
for(int i = 1; i < n; i++){
cin >> b;
d.push_back(b - a - 1);
a = b;
}
sumd = b + 1 - sumd;
sort(d.begin(), d.end(), comp);
for(int i = 0; i < k - 1; i++){
sumd -= d[i];
}
cout << sumd;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |