地址 https://www.papamelon.com/problem/193
解答
根据题意,蚂蚁a和b相遇后各自反向,起始就等于a和b穿过对方继续行走。所以没有任何干扰,就是求每个蚂蚁向左或者向右的最大最小时间
#include <iostream>
#include <algorithm>
#include <memory.h>
using namespace std;
const int N = 1000010;
int arr[N];
int t, n, m;
int main()
{
cin >> t;
while (t--) {
memset(arr, 0, sizeof arr);
cin >> m >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int a = -1; int b = -1;
for (int i = 0; i < n; i++) {
a = max(a, min(m - arr[i], arr[i]));
b = max(b, max(m - arr[i], arr[i]));
}
cout << a << " " << b << endl;
}
return 0;
}