# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1005951 | thangdz2k7 | Wiring (IOI17_wiring) | C++17 | 0 ms | 0 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;
long long min_total_length(vector <int> &r, vector <int> &b){
int n = r.size(), m = b.size();
vector < pair <int, int> > point;
int cnt = 0;
for (int p : r) point.push_back(pair <int, int> (p, cnt)), ++ cnt;
for (int p : b) point.push_back(pair <int, int> (p, cnt)), ++ cnt;
sort(point.begin(), point.end());
long long ans = 0;
int num = 0;
for (int i = 0; i < cnt - 1; ++ i){
auto [p, id] = point[i];
if (id < n) ++ num;
else -- num;
auto [_next, nid] = point[i + 1];
ans += 1ll * abs(num) * (_next - p);
}
return ans;
}