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, matches;
cin >> n >> matches;
vector<int> times(n);
for (int i = 0; i < n; i++)
{
cin >> times[i];
}
int total_time = times.back() + 1 - times.front();
matches--;
vector<int> diff(n - 1);
for (int i = 0; i < n - 1; i++) {
diff[i] = times[i + 1] - times[i] - 1;
}
// largest first
sort(diff.rbegin(), diff.rend());
for (int i = 0; i < n - 1; i++) {
if (matches == 0) {
break;
}
matches--;
total_time -= diff[i];
}
cout << total_time;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |