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 solve(int K, vector<int> & times) {
int N = (int) times.size();
vector<int> gaps(N-1);
for (int i = 0; i < N-1; i++)
gaps[i] = times[i+1]-times[i]-1;
sort(gaps.begin(), gaps.end(), greater<int>());
int answer = times[N-1]+1 - times[0];
for (int i = 0; i < K-1; i++) {
answer -= gaps[i];
}
return answer;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int N, K;
vector<int> times;
cin >> N >> K;
times = vector<int>(N);
for (int i = 0; i < N; i++)
cin >> times[i];
cout << solve(K, times) << '\n';
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... |