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 <queue>
using namespace std;
const int NMAX = 1e5;
int N, K, a[NMAX + 2];
priority_queue < int > pq;
int main()
{
cin >> N >> K;
for(int i = 1; i <= N; i++)
cin >> a[i];
int ans = a[N] + 1 - a[1];
for(int i = 2; i <= N; i++)
pq.push(a[i] - a[i - 1] - 1);
for(int i = 1; i < K; i++)
ans -= pq.top(), pq.pop();
cout << ans << '\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... |