CRISPRCas9 @ 2021-02-22 08:16:18
#include<iostream>
#include<algorithm>
#define N 1000010
using namespace std;
typedef long long LL;
LL school[N];
LL m, n, x;
LL ans = 0;
int main()
{
cin >> m >> n;
for(int i = 0; i < m; i++)
cin >> school[i];
sort(school, school + m);
for(int i = 0; i < n; i++)
{
cin >> x;
LL a = lower_bound(school, school + m, x) - school;
//特判
if(a == m)
ans += x - school[m];
else
{
if(a == 0)
ans += school[0] - x;
else
{
LL tmp_1 = school[a] - x;
LL tmp_2 = x - school[a - 1];
ans += min(tmp_1, tmp_2);
}
}
}
cout << ans;
return 0;
}
by 天南星魔芋 @ 2021-02-22 09:05:49
@CRISPRCas9 第21行
by 天南星魔芋 @ 2021-02-22 09:07:42
by CRISPRCas9 @ 2021-02-23 10:32:11
@天南星魔芋 额,21行有什么问题?能具体说说嘛
by 天南星魔芋 @ 2021-02-23 10:48:35
@CRISPRCas9 你
by CRISPRCas9 @ 2021-02-23 14:13:47
@天南星魔芋 懂了懂了,我粗心了,谢谢兄弟