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 fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5+10;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
ll min_total_length(vector<int> r, vector<int> b) {
int n=(int)r.size(), m=(int)b.size();
if(n>m){
swap(n, m);
swap(r, b);
}
r.pb(-1e9-2);
ll ans=0;
int last=0;
for(int i=0;i<n;i++){
int low=last+1, high=m-n+i, best=last;
while(low<=high){
int mid=(low+high)>>1;
if(abs(b[mid]-r[i])<=abs(b[mid]-r[i+1])){
best=mid;
low=mid+1;
}
else high=mid-1;
}
while(last<=best){
ans+=abs(b[last]-r[i]);
last++;
}
}
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... |