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 N 300005
#define ll long long int
#define sz(x) (int)x.size()
#define ff first
#define ss second
int T, n, a[N], k;
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
sort(a+1,a+n+1);
vector <int> v;
for(int i = 1; i < n; i++){
v.push_back(a[i+1]-a[i]-1);
}
sort(v.rbegin(), v.rend());
int ans = n;
k -= n;
while(sz(v) > 0 and k < 0){
k++;
ans += v.back();
v.pop_back();
}
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... |