| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1291916 | thaibeo123 | Stove (JOI18_stove) | C++20 | 14 ms | 1480 KiB |
#include <bits/stdc++.h>
using namespace std;
#define NAME "A"
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define MASK(x) (1ll << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
const int N = 1e5 + 5;
int n, k;
int a[N];
vector<int> v;
void input() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
}
void solve() {
int ans = a[n] - a[1] + 1;
for (int i = 2; i <= n; i++) {
v.pb(a[i] - a[i - 1] - 1);
}
k--;
sort(all(v), greater<>());
for (int i = 0; i < k; i++) {
ans -= v[i];
}
cout << ans;
}
signed main() {
if (fopen(NAME".INP", "r")) {
freopen(NAME".INP", "r", stdin);
freopen(NAME".OUT", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
input();
solve();
return 0;
}
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... | ||||
