Submission #748544

#TimeUsernameProblemLanguageResultExecution timeMemory
748544Desh03Wiring (IOI17_wiring)C++17
13 / 100
67 ms13192 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...