我下载了样例一的测试点,测试点的n ,m 分别是429,517。
但是我的代码没有办法输入到429,即使手动输入也没有办法,这是为什么呢?
#include<bits/stdc++.h>
#define IO std::ios::sync_with_stdio(0),cin.tie(0)
using namespace std;
typedef long long ll;
const int N=2e7+10;
int c[N];
typedef struct{
ll num;
int a;
int b;
}STU;
STU stu[N];
ll cmp(STU s1,STU s2)
{
return s1.num < s2.num;
}
int main()
{
IO ;
ll m,n,len=0;
cin>>n>>m;
for(int i=0;i<n;i++)
{
cin>>stu[len].num;
stu[len].a=1;stu[len].b=0;
len++;
}
for(int i=0;i<m;i++)
{
cin>>stu[len].num;
stu[len].a=0,stu[len].b=1;
len++;
}
sort(stu,stu+len,cmp);
ll res_a=-1,res_b=-1,sum=0,pa,pb;
for(int i=0;i<len;i++)
{
if(stu[i].a)
{
res_a=stu[i].num;
pa=i;
}
if(stu[i].b)
{
res_b=stu[i].num;
pb=i;
}
if(res_a>=0&&res_b>=0)
{
sum+=abs(res_a-res_b);//printf("a=%lld b=%lld sum=%lld \n",res_a,res_b,sum);
stu[pa].a=0;
stu[pb].b=0;
res_a=-1,res_b=-1;
}
}
res_a=-1,res_b=-1,pa,pb;
for(int i=len-1;i>=0;i--)
{
if(stu[i].a)
{
res_a=stu[i].num;
pa=i;
}
if(stu[i].b)
{
res_b=stu[i].num;
pb=i;
}
if(res_a>=0&&res_b>=0)
{
sum+=abs(res_a-res_b);//printf("a=%lld b=%lld sum=%lld \n",res_a,res_b,sum);
stu[pa].num=-1;
stu[pb].num=-1;
res_a=-1,res_b=-1;
}
}
printf("%lld\n",sum);
return 0;
}