#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define LB lower_bound
#define UB upper_bound
#define ii pair<int, int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>
#define vs vector<string>
#define vii vector<ii>
#define vvii vector<vii>
#define vll vector<ll>
#define vld vector<ld>
#define pld pair<ld, ld>
#define vpld vector<pair<ld, ld>>
int n, k;
vi v;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
v.resize(n);
for (int &i : v) cin >> i;
sort(all(v));
priority_queue<ii> dis;
for (int i = 0; i+1 < n; i++) {
dis.push(mp(-(v[i+1]-v[i]+1), i));
}
vb vis(n, 0);
int ans = 0;
int x = n;
while (k < x) {
ii curr = dis.top();
dis.pop();
ans += -curr.ff;
vis[curr.ss] = vis[curr.ss+1] = 1;
x--;
}
for (int i = 0; i < n; i++) if (!vis[i]) ans++;
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |