SiberianRoe_ @ 2024-01-05 21:03:40
#include <bits/stdc++.h>
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int m,n;
cin >> m >> n;
const int M = m,N = n;
int school[M],student[N];
for(int i = 0;i < m;i++)
cin >> school[i];
for(int i = 0;i < n;i++)
cin >> student[i];
sort(school,school+m);
int lis[N];
for(int i = 0;i < n;i++)
{
lis[i]=abs(student[i]-*lower_bound(school,school+m,student[i]));
}
sort(school,school+m,cmp);
unsigned long long sum = 0;
for(int i = 0;i < n;i++)
{
int temp = abs(student[i]-*lower_bound(school,school+m,student[i],cmp));
if(temp < lis[i])
lis[i]=temp;
sum+=lis[i];
}
cout << sum;
return 0;
}
by SiberianRoe_ @ 2024-01-05 21:15:30
STL 似乎比较容易出事,,,