dfydada⚡⚡⚡ @ 2019-08-14 14:55:08
这是我的代码,求解~
#include<bits/stdc++.h>
//#pragma GCC optimize(2)//O2优化
using namespace std;
typedef long long ll;
typedef long double ld;
const int N=200000+10;
ll n,m;
ll tot,ans,ant,any,num;
struct asd
{
ll x,y;
}a[N];
ll read()
{
ll res=0,chr=getchar(),st=1;
if(chr=='-')
{
st=-1;
}
while(!isdigit(chr)&&chr!=EOF)
{
chr=getchar();
}
while(isdigit(chr))
{
res=(res*10)+(chr-'0');
chr=getchar();
}
return res*st;
}
bool bll(asd l,asd r)
{
return l.x<r.x;
}
int main()
{
n=read();
m=read();
for(int i=1;i<=n;i++)
{
tot++;
a[tot].x=read();
}
for(int i=1;i<=m;i++)
{
tot++;
a[tot].x=read();
a[tot].y=1;
}
sort(a+1,a+1+tot,bll);
for(int i=1;i<=tot;i++)
{
if(a[i].y!=1)
{
ans=a[i].x;
}
else
{
if(i<=ant)
{
num+=min(abs(ans-a[i].x),abs(any-a[i].x));
}
else
{
ant=i;
while(ant<=tot)
{
ant++;
if(a[ant].y!=1)
{
any=a[ant].x;
break;
}
}
num+=min(abs(ans-a[i].x),abs(any-a[i].x));
}
}
}
cout<<num;
return 0;
}
by 千反田 @ 2019-08-21 17:49:20
有点好奇您切了那么多黄绿蓝题为啥要在讨论区里问一道橙题