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;
int main() {
int n, m;
cin >> n >> m;
vector <long long> a(n);
vector <long long> dif;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n - 1; i++)
if (a[i+1] - a[i] > 1)
dif.push_back(a[i+1] - a[i] - 1);
sort(dif.begin(),dif.end());
int s = dif.size();
long long suma = a[n-1] + 1 - a[0];
for (int i = 0; i < m - 1 && s - 1 - i >= 0; i++)
suma -= dif[s - 1 - i];
cout << suma;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |