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>
#include "wiring.h"
using namespace std;
#define OYY LLONG_MAX
#define mod 1000000007
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define FOR for(int i=1;i<=n;i++)
#define mid (start+end)/2
#define lim 2000005
#define fi first
#define se second
typedef long long lo;
int a[lim],bt[lim];
long long min_total_length(std::vector<int> r, std::vector<int> b) {
int n=r.size();
int m=b.size();
for(int i=0;i<n;i++)a[i+1]=r[i];
for(int i=0;i<m;i++)bt[i+1]=b[i];
if(n>m){
swap(n,m);
swap(a,bt);
}
lo cev=0;
FOR{
cev+=abs(a[i]-bt[i]);
}
int cur=1;
for(int i=n+1;i<=m;i++){
while(cur<n && a[cur]<bt[i])cur++;
int tut=abs(a[cur]-bt[i]);
if(cur!=1)tut=min(tut,abs(a[cur-1]-bt[i]));
cev+=tut;
}
return cev;
}
# | 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... |