이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cerr << #x << " = " << x << "\n";
#define deb2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << "\n";
#define deb3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << "\n";
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
typedef long long ll;
void solve() {
int n, k;
cin >> n >> k;
vector<int> ent(n);
for (int i = 0; i < n; ++i) {
cin >> ent[i];
}
priority_queue<int> pq;
sort(all(ent));
for (int i = 0; i < n-1; ++i) {
pq.push(ent[i+1] - ent[i] - 1);
}
int a = 0;
for (int i = 0; i < k-1 && !pq.empty(); ++i) {
a+= pq.top();
pq.pop();
}
cout << (ent[n-1] - ent[0] - a + 1);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
ll tc = 1;
//cin >> tc;
while(tc--) {
solve();
cout << '\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... |