遇到考研笔试出贪心的问题,不要怂你感觉怎么想合理就怎么来,不需要证明浪费时间,多考虑常识的算法思想成功率就很高
没啥说的,组团,求差值,差值用最大跟最小绝对值的二倍表示就行了,如果遇到相同的直接取最前面的即可
#include <iostream>
#include <cstring>
#include <algorithm>
#define N 100010
using namespace std;
typedef long long LL;
int l, m, n;
int a[N], b[N], c[N];
int main()
{
scanf("%d%d%d", &l, &n, &m);
for (int i = 0;i < l;i ++) scanf("%d", &a[i]);
for (int i = 0;i < n;i ++) scanf("%d", &b[i]);
for (int i = 0;i < m;i ++) scanf("%d", &c[i]);
LL res = 1e18;
for (int i = 0, j = 0, k = 0; i < l && j < n && k < m;)
{
int x = a[i], y = b[j], z = c[k];
res = min(res, (LL)max(max(x, y), z) - min(min(x, y), z));
if(x <= y && x <= z) i ++;
else if(y <= x && y <= z) j ++;
else k ++;
}
printf("%lld\n", res * 2);
return 0;
}