# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1241941 | hanguyen | Stove (JOI18_stove) | C++20 | 13 ms | 2244 KiB |
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5 + 5 ;
int n , k;
int a[maxn];
vector<int>res;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if (fopen(".inp", "r")) {
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
}
cin >> n >> k;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
for(int i = 1; i < n; i++) {
int diff = a[i + 1] - a[i] - 1;
res.push_back(diff);
}
sort(res.begin(),res.end());
int ans = n;
for(int i = 0; i < n - k; i++) ans += res[i];
cout << ans;
}
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... |