이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int n, k;
int ans = 0;
int arr[101010];
priority_queue<int, vector<int>, greater<int>> pq;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n >> k;
for (int i=0; i<n; i++) cin >> arr[i];
sort(arr, arr+n);
for (int i=0; i<n-1; i++) {
pq.push(arr[i+1]-arr[i]-1);
}
for (int i=0; i<n-k; i++) {
ans += pq.top();
pq.pop();
}
ans += n;
cout << ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |