# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1005952 | 2024-06-23T08:56:18 Z | thangdz2k7 | Wiring (IOI17_wiring) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; long long min_total_length(vector <int> &r, vector <int> &b){ int n = r.size(); int 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; }