#include <bits/stdc++.h>
#define ll long long
#define sz(x) int(x.size())
#define forn(i,n) for(i=0; i<n; i++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fr first
#define se second
using namespace std;
long long min_total_length(std::vector<int> r, std::vector<int> b) {
vector<ll>a,v;
for(auto k:r)
a.pb(k);
for(auto k:b)
v.pb(k);
ll tot=0;
if(sz(a)<=sz(v))
{
ll i=sz(a)-1, j=sz(v)-1;
while(i<j)
{
tot=tot+abs(a[i]-v[j]);
j--;
}
while(i>=0)
{
tot=tot+abs(a[i]-v[j]);
i--;
j--;
}
}
else
{
ll i=sz(a)-1, j=sz(v)-1;
while(i>=0&&j>=0)
{
tot=tot+abs(a[i]-v[j]);
i--;
j--;
}
while(i>=0)
{
tot=tot+abs(a[i]-v[0]);
i--;
}
}
return tot;
}
# | 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... |