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;
long long t[100001];
int main(void)
{
long long n,k,ans;
cin>>n>>k;
k--;
priority_queue<long long> q;
for(int i=0;i<n;i++)
{
cin>>t[i];
}
q.push(0);
for(int i=1;i<n;i++)
{
q.push(t[i]-t[i-1]-1);
}
ans=t[n-1]-t[0]+1;
while(k--)
{
ans=ans-q.top();
q.pop();
}
cout<<ans;
return 0;
}
/*
3 3
1
3
6
1 0
3 1
6 2
10 5
1
2
5
6
8
11
13
15
16
20
1 0 1->3
2 0
5 2 5->9
6 0
8 1
11 2 11->14
13 1
15 1 15->17
16 0
20 3 20->21
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |