#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int a[100], n,L;
scanf("%d%d", &n,&L);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
int record=0;
for (int i = 1; i <= n; i++)
{
record = max(min(L-a[i],a[i]),record );//6 4 4 2 4
}
int record2 = 0;
for (int i = 1; i <= n; i++)
{
record2 = max(max(a[i],L-a[i]), abs(record2));
}
cout << record<<'\n'<<record2;
return 0;
}
第一个max代表更新遍历每一个蚂蚁的路径 ,嵌套的max(min)代表是选择合适的路径
模拟过程成功就恍然大悟了,因为每一个蚂蚁掉头相当于相互穿过去