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 INF = 0x3f3f3f3f;
long long min_total_length(std::vector<int> r, std::vector<int> b) {
if (r.size() > b.size()) r.swap(b);
long long res = 0;
for (int i = 0; i < (int)r.size(); i++)
res += abs(r[i] - b[i]);
int sz = r.size();
r.insert(r.begin(), -INF);
r.push_back(INF);
for (int i = sz; i < (int)b.size(); i++) {
auto nx = lower_bound(r.begin(), r.end(), b[i]), pr = nx - 1;
int mn = INT_MAX;
if (*nx != INF)
mn = min(mn, *nx - b[i]);
if (*pr != -INF)
mn = min(mn, b[i] - *pr);
res += mn;
}
return res;
}
# | 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... |