# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1151031 | thiendeptrai | Stove (JOI18_stove) | C++20 | 16 ms | 2244 KiB |
#include <bits/stdc++.h>
#define task "stove"
#define int long long
#define ii std::pair<int, int>
#define iii std::pair<ii, int>
#define fi first
#define se second
#define pb push_back
#define ins insert
const int maxn = 1e5;
int n, k;
int a[maxn + 7], f[maxn + 7];
signed main()
{
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
std::cout.tie(0);
if (std::fopen(task ".inp", "r"))
{
std::freopen(task ".inp", "r", stdin);
std::freopen(task ".out", "w", stdout);
}
std::cin >> n >> k;
for (int i = 1; i <= n; i++)
{
std::cin >> a[i];
}
int ans = a[n] - a[1] + 1;
std::vector<int> v;
for (int i = 1; i < n; i++)
{
v.pb(a[i + 1] - a[i] - 1);
}
std::sort(v.begin(), v.end(), std::greater<int>());
for (int i = 0; i < k - 1; i++)
{
ans -= v[i];
}
std::cout << ans;
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... |