# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
170261 | Akashi | Stove (JOI18_stove) | C++14 | 27 ms | 2168 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 <bits/stdc++.h>
using namespace std;
int n, k;
int a[100005], b[100005];
int main()
{
scanf("%d%d", &n, &k);
--k;
int Sum = 0, Max = 0, Min = 2e9;
for(int i = 1; i <= n ; ++i){
scanf("%d", &a[i]);
if(i > 1) b[i] = a[i] - a[i - 1] - 1;
Max = max(Max, a[i]);
Min = min(Min, a[i]);
}
Sum = Max - Min + 1;
sort(b + 1, b + n + 1);
for(int i = n; i > n - k ; --i) Sum -= b[i];
printf("%d", Sum);
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... |