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;
long long i,j,k,a,n,m,cur,sk,l,ab[200005],rez;
vector<long long> xx,mas;
long long min_total_length(vector<int> r,vector<int> b)
{
n=r.size();
m=b.size();
i=0;
j=0;
sk=0;
cur=-1;
while (i<n&&j<m)
{
if (r[i]<b[j])
{
if (cur==0)
{
sk++;
}
else
{
if (sk>0)
{
xx.push_back(sk);
}
sk=1;
cur=0;
}
mas.push_back(r[i]);
i++;
}
else
{
if (cur==1)
{
sk++;
}
else
{
if (sk>0)
{
xx.push_back(sk);
}
sk=1;
cur=1;
}
mas.push_back(b[j]);
j++;
}
}
ab[0]=mas[0];
i=1;
while (i<n+m)
{
ab[i]=ab[i-1]+mas[i];
i++;
}
j=0;
a=0;
k=1;
l=xx[0];
i=xx[0];
while (i<n+m)
{
if (l>0)
{
rez+=mas[i];
rez-=mas[j];
j++;
l--;
}
a++;
if (a>=xx[k])
{
if (l>0)
{
while (l>0)
{
rez+=mas[i-a+1]-mas[j];
j++;
l--;
}
l=0;
}
else
{
j=i;
}
k++;
}
i++;
}
cout << rez;
return 0;
}
# | 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... |