#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int n, minL = 0, maxL = 0 ;
cin>>n;
int l,pos,num;
while(n--)
{
cin>>l>>num;
for(int i = 0; i<num; i++)
{
cin>>pos;
int temp = min(pos,l - pos);
minL = max(minL,temp);//最短 (递归不要开数组了)
temp = max(pos,l - pos);
maxL = max(maxL,temp); //最长
}
cout<<minL<<" "<<maxL<<endl;
}
return 0;
}
思路来源于蚂蚁相遇问题的巧解_n 只蚂蚁以每秒 1cm 的速度在长为 lcm 的竿子上爬行。当蚂蚁爬到竿子的端点时就会-CSDN博客
很妙的方法
声明:仅用于学习,严禁复制代码直接提交Levoj