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 int long long int
#define pb push_back
#define st first
#define nd second
#define lb lower_bound
const int N = 4000050;
int n, k, a, b, mak;
priority_queue<int> v;
vector<int> u;
int32_t main(){
cin >> n >> k;
k--;
for (int i = 0; i < n; i++){
cin >> a;
u.pb(a);
}
sort(u.begin(), u.end(), greater<int>());
for (int i = 0; i < n-1; i++){
v.push(u[i]-u[i+1]);
// cout << u[i]-u[i+1] << endl;
}
while(k > 0){
k--;
// cout << v.top()-1 << endl;
mak -= (v.top()-1);
v.pop();
}
cout << u[0]+mak << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |