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>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll inf = 1e18;
const int i_inf = 1e9;
const ll mod = 1e9+7;
mt19937 _rand(time(NULL));
const int mxn = 5e5+5;
#include "wiring.h"
bool ok[mxn];
long long min_total_length(std::vector<int> r, std::vector<int> b){
vector<pair<int,bool> > v;
for(auto u : r) v.pb({u, 0});
for(auto u : b) v.pb({u, 1});
sort(all(v));
int n = (int)v.size();
ll ans = 0;
fr(i, 0, n){
fr(j, 0, i){
if(v[i].nd != v[j].nd){
if(!ok[j]){
ans += (v[i].st - v[j].st);
ok[i] = ok[j] = true;
break;
}
}
}
}
fr(i, 0, n){
if(ok[i]) continue;
for(int j = i-1; j >= 0; j --){
if(v[i].nd != v[j].nd){
ans += v[i].st-v[j].st;
break;
}
}
}
return ans;
}
/*
int main(){
cout<<min_total_length({1, 2, 3, 7}, {0, 4, 5, 9, 10});
}
*/
# | 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... |