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;
const int N = 1e5 + 10;
int n , k , ar[N];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> k; k--;
for(int i = 0 ; i < n ; i++)
cin >> ar[i];
priority_queue <int> pq;
int ans = ar[n - 1] - ar[0] + 1;
for(int i = 1 ; i < n ; i++)
pq.push(ar[i] - ar[i - 1] - 1);
while(k--)
{
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... |