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>
#define nmax 100010
#define ll long long
using namespace std;
int n,k,a[nmax];
ll res;
priority_queue<int,vector<int>,greater<int> > pq;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>k;
for (int i=1;i<=n;++i)
{
cin>>a[i];
if (i>1) pq.push(a[i]-a[i-1]-1);
}
res=n; k=n-k;
while (k>0)
{
res+=pq.top(); pq.pop();
--k;
}
cout<<res;
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... |