# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
880987 | theghostking | Stove (JOI18_stove) | C++17 | 56 ms | 5320 KiB |
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
signed main() {
int n,k;
cin >> n >> k;
if (n==1){
cout << "1\n";
return 0;
}
int arr[n];
for (int i = 0; i<n; i++){
cin >> arr[i];
}
sort(arr,arr+n);
vector<bool> pres(n);
pres[0] = true;
priority_queue<pair<int,int>> pq;
for (int i = 0; i<n-1; i++){
pq.push({arr[i+1]-arr[i],i});
}
int kc = k;
k--;
while (k--){
pres[pq.top().second+1] = true;
pq.pop();
}
vector<int> nxt(n,-1);
int tr = 0;
for (int i = 1; i<n; i++){
if (pres[i]){
nxt[tr] = i-1;
tr = i;
}
}
int lst = arr[0];
int ind = 0;
int ans = 0;
for (int i = 0; i<n; i++){
if (pres[i]){
int nd = nxt[i];
if (nd == -1){
ans += (arr[n-1]-arr[i]+1);
}
else{
ans += (arr[nd]-arr[i]+1);
}
}
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |