题目链接
思路
蚂蚁相遇后掉头与穿过效果等同
时间复杂度
$$ 每组O(N) $$
代码
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
int T;
scanf("%d", &T);// don't forget &
while (T--) {
int len, n;
scanf("%d%d", &len, &n);// don't forget &
int mi = 0, mx = 0;
while (n--) {
int x;
scanf("%d", &x);// don't forget &
mi = max(mi, min(len - x, x));
mx = max(mx, max(len - x, x));
}
printf("%d %d\n", mi, mx);
}
return 0;
}