# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1162598 | Isa2011 | Stove (JOI18_stove) | C11 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define int long long
#define fr first
#define sc second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
int mod = 1e9 + 7;
const int N = 2 * 1e5;
void solve() {
int n,m;
cin >> n >> m;
vector<int> a(n);
for (auto &it : a)
cin >> it;
sort(all(a));
vector<int> ans;
for (int i = 1; i < n; i++)
ans.pb(a[i] - a[i-1] + 1);
sort(all(ans));
int h = n / m;
int an = 0;
for (int i = 0; i < h; i++) {
an += ans[i];
}
cout << an + h;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// Isa2011
solve();
}