lastlonely_tears @ 2024-11-05 20:12:49
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include<iostream>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
int m, n,ans=0;
cin >> m >> n;
priority_queue<int>uni;
priority_queue<int>stu;
int minx = 2147483647;
int aa, bb;
for (int i = 1; i <= m; i++)
{
cin >> aa;
uni.push(aa);
}
for (int i = 1; i <= n; i++)
{
cin >> bb;
stu.push(bb);
}
while (!stu.empty())
{
minx = min(minx, abs(uni.top() - stu.top()));
int cc = uni.top();
if (uni.size() > 1)
{
uni.pop();
if (abs(uni.top() - stu.top()) > minx)
{
stu.pop();
ans += minx;
minx = 2147483647;
uni.push(cc);
}
}
else
{
ans += abs(uni.top() - stu.top());
stu.pop();
}
}
cout << ans << endl;
return 0;
}
by K_yuxiang_rose @ 2024-11-12 19:46:46
@lastlonely_tears 不开long long见祖宗(求关