# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41101 | abeker | Stove (JOI18_stove) | C++14 | 32 ms | 1624 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 MAXN = 1e5 + 5;
int N, K;
int t[MAXN];
vector <int> gaps;
void load() {
scanf("%d%d", &N, &K);
for (int i = 0; i < N; i++)
scanf("%d", t + i);
}
int solve() {
int last = t[0];
int cnt = 1, sol = 0;
for (int i = 1; i < N; i++)
if (t[i] - t[i - 1] > 1) {
sol += t[i - 1] - last + 1;
gaps.push_back(t[i] - t[i - 1] - 1);
last = t[i];
cnt++;
}
sol += t[N - 1] - last + 1;
sort(gaps.begin(), gaps.end());
for (int i = 0; i < cnt - K; i++)
sol += gaps[i];
return sol;
}
int main() {
load();
printf("%d\n", 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... |