一生蒟蒻 @ 2023-01-29 19:07:40
#include <bits/stdc++.h>
using namespace std;
long long school,student,k,cnt,ans,a[1000010],b[1000010];
int main()
{
cin>>school>>student;
for(int i = 0 ; i < school ; i ++)
{
cin>>a[i];//学校
}
for(int i = 0 ; i < student ; i ++)
{
cin>>b[i];//学生
}
for(int i = 0 ; i < student ; i++)
{
cnt = INT_MAX;
for(int j = 0 ; j < school ; j++)
{
if(abs(b[i] - a[j]) < cnt)
{
cnt = abs(b[i] - a[j]);
}
}
ans += cnt;
}
cout<<ans;
return 0;
}
懵了,五个TLE
by zh13910192180 @ 2023-02-06 16:03:05
用二分..
你也不看看数据范围...
by zh13910192180 @ 2023-02-06 16:28:27
ans=0呢???
by fengyongrui @ 2023-03-01 17:39:37
二分,暴力枚举必然超时!
有个东西叫lower_bound,还有个东西叫upper_bound!