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 "wiring.h"
#include<bits/stdc++.h>
using namespace std;
#define N 200100
int n, m, a[N];
long long ans = 0;
long long min_total_length(vector<int> r, vector<int> b)
{
n = r.size();
m = b.size();
for (int i=0; i<n; i++)
{
long long mn = 1e18;
int k = 0;
for (int j=0; j<m; j++)
{
if (abs(r[i] - b[j]) <= mn) mn = abs(r[i] - b[j]), k = j;
}
a[k]++;
ans += mn;
}
for (int i=0; i<m; i++)
{
if (a[i] == 0)
{
long long mn = 1e18;
for (int j=0; j<n; j++)
mn = min(mn, 1ll*abs(b[i] - r[j]));
for (int j=0; j<m; j++)
mn = min(mn, 1ll*abs(b[i] - b[j]));
ans += mn;
}
}
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... |