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;
#define ll long long
#define endl "\n"
int n, k;
vector<int> t;
vector<int> raz;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>k;
for(int i = 1;i<=n;i++)
{
int a;
cin>>a;
t.push_back(a);
}
sort(t.begin(),t.end());
for(int i = 1;i<(int)t.size();i++)
{
raz.push_back(t[i]-t[i-1]-1);
}
sort(raz.begin(),raz.end(),greater<int>());
int sum = 0;
for(int i = 0;i<k-1;i++)
sum+=raz[i];
cout<<t[n-1] - t[0] + 1 - sum;
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... |