# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1033523 | sp69t | Stove (JOI18_stove) | C++14 | 14 ms | 2140 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <algorithm>
int a[100100], s[100100];
int main() {
int n, k, res; scanf("%d %d", &n, &k);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
res = a[n] - a[1] + 1;
for (int i = 1; i < n; ++i) s[i] = a[i + 1] - a[i] - 1;
std::sort(s + 1, s + n);
// for (int i = 1; i < n; i++) printf("%d ", s[i]);
// printf("\n");
for (int i = 0, j = n - 1; i < k - 1 && j; ++i, --j) res -= s[j];
printf("%d", res);
}
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... |