# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41577 | szawinis | Stove (JOI18_stove) | C++14 | 34 ms | 2068 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;
const int N = 1e5+1;
int n, k, ans, a[N];
priority_queue<int> segs;
int main() {
scanf("%d %d", &n, &k);
for(int i = 1; i <= n; i++) {
scanf("%d", a+i);
if(i > 1 && a[i] - a[i-1] > 1) segs.push(a[i] - a[i-1] - 1);
}
ans = a[n] - a[1] + 1;
for(int i = 1; i < k && !segs.empty(); i++) {
ans -= segs.top();
segs.pop();
}
printf("%d", ans);
}
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... |