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;
int main() {
int n,k; cin >> n >> k; k--;
vector<int> times(n),timediffs;
for (int i=0;i<n;i++) {
cin >> times[i];
}
for (int i=0;i<n-1;i++) {
timediffs.push_back(times[i+1]-times[i]);
}
int ans = times[n-1];
sort(timediffs.begin(),timediffs.end(),greater<int>());
for (int i=0;i<k;i++) {
ans -= (timediffs[i]-1);
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |