# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
482834 | glome | Stove (JOI18_stove) | C++17 | 0 ms | 204 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 main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n,k;
cin >> n >> k;
vector<pair<int, int>> d;
vector<int> y(n);
for (int i = 0; i<n; i++) {
cin >> y[i];
}
for (int i = 0; i<n-1; i++) {
if(y[i] + 1 == y[i + 1]) {
continue;
}
d.push_back({y[i] + 1, y[i+1] - 1});
}
sort(d.begin(), d.end(), [&] (pair<int, int> A, pair<int, int> B) {
return A.second - A.first > B.second - B.first;
});
map<int, bool> mark;
for (int i = k - 1; i<d.size(); i++) {
mark[d[i].first - 1] = 1;
}
int ans = 0;
for (int i = 0; i<n - 1; i++) {
if(mark[y[i]]) {
if(i == 0) {
ans += (y[i + 1] + 1) - y[i];
continue;
}
if(mark[y[i-1]]) {
ans += y[i + 1] - y[i];
}
else {
ans +=( y[i + 1] + 1) - y[i];
}
}
else {
ans++;
}
}
if(n == 1) {
ans++;
}
if(n >= 2) {
if(!mark[y[n-2]]) {
ans++;
}
}
cout << ans << '\n';
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... |