#include "wiring.h"
#include <bits/stdc++.h>
typedef long long ll;
#define ar array
using namespace std;
long long min_total_length(std::vector<int> r, std::vector<int> b) {
queue<int> fila[2];
int last[2] = {0, 0};
vector<ar<int,2>> v;
for(int x : r) v.push_back({x, 0});
for(int x : b) v.push_back({x, 1});
sort(v.begin(), v.end());
long long ans = 0;
for(auto [x, c] : v){
if(!fila[!c].empty()){
last[c] = x;
last[!c] = fila[!c].front();
fila[!c].pop();
ans += x - last[!c];
}
else fila[c].push(x);
}
if(fila[0].empty()){
swap(fila[0], fila[1]);
swap(last[0], last[1]);
}
while(!fila[0].empty()){
ans += fila[0].front() - last[1];
fila[0].pop();
}
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... |