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 "wiring.h"
#include <bits/stdc++.h>
using namespace std;
long long min_total_length(vector<int> r_, vector<int> b_) {
set<int> r(r_.begin(), r_.end()), b(b_.begin(), b_.end());
long long ans = 0;
for (int x : r) {
if (b.empty()) {
auto it = upper_bound(b_.begin(), b_.end(), x);
if (it == b_.end()) --it;
else if (it != b_.begin() && x - *prev(it) < *it - x) --it;
ans += abs(*it - x);
} else {
auto it = b.upper_bound(x);
if (it == b.end()) --it;
else if (it != b.begin() && x - *prev(it) < *it - x) --it;
ans += abs(*it - x);
b.erase(it);
}
}
for (int x : b) {
auto it = r.upper_bound(x);
if (it == r.end()) --it;
else if (it != r.begin() && x - *prev(it) < *it - x) --it;
ans += abs(*it - x);
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |