| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1355772 | truongthaiduonglaptrinh | Stove (JOI18_stove) | C++20 | 16 ms | 1212 KiB |
// duonglaptrinh
# include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
bool find_Max(int &ans, int x) {
// cout<<x<<"\n";
if(x == -1) {
return 0;
}
ans = min(ans, x);
return 1;
}
int n, k;
int a[N], b[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if(fopen("nhap.inp", "r")) {
freopen("nhap.inp", "r", stdin);
freopen("nhap.out", "w", stdout);
}
cin>>n>>k;
for(int i = 1; i <= n; i++) {
cin>>a[i];
}
sort(a + 1, a + 1 + n);
for(int i = 1; i < n; i++) {
b[i] = (a[i + 1] - a[i] - 1);
}
sort(b + 1, b + n, greater<>());
int ans = a[n] - a[1] + 1;
for(int i = 1; i <= min(n - 1, k - 1); i++) {
ans -= b[i];
}
cout<<ans;
return 0;
}
Compilation message (stderr)
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
