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;
using ll = long long;
template<class T> bool cmin(T &i, T j) { return i > j ? i=j,true:false; }
template<class T> bool cmax(T &i, T j) { return i < j ? i=j,true:false; }
const int nax = 100100;
int a[nax],b[nax],n,k;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
for (int i=0;i<n;i++) {
cin >> a[i];
}
for (int i=0;i<n-1;i++) {
b[i] = a[i+1]-a[i]-1;
}
sort(b,b+n-1);
reverse(b,b+n-1);
int ans = a[n-1] - a[0] + 1;
for (int i=0;i<k-1;i++) {
ans -= b[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... |