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>
typedef long long ll;
using namespace std;
int main()
{
ios_base::sync_with_stdio();cin.tie(nullptr);
ll n, k;
cin>>n>>k;
vector<ll> a;
for(int i = 0; i < n; i++){
ll aa;
cin>>aa;
a.push_back(aa);
}
vector<ll> s;
for(int i = 0; i < n-1; i++){
s.push_back(a[i+1]-a[i]-1);
}
ll all=a[n-1]+1-a[0];
if(k>=n)cout<<n;
else{
sort(s.begin(), s.end());
reverse(s.begin(), s.end());
for(int i = 0; i < k-1; i++){
//cout<<s[i]<<endl;
all-=s[i];
}
cout<<all;
}
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... |