【YZOJ】0821-T1(蚂蚁)题解

水题,蚂蚁相遇后可考虑为直接穿过,因为蚂蚁的移速一样,另一只蚂蚁会走完原来蚂蚁的路线。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("ant.in");
ofstream fout("ant.out");
int n, l, min_ans = -114514, max_ans = -1919810;
int main() {
fin >> n >> l;
for(int i = 1; i <= n; i++) {
int llen, rlen;
fin >> llen;
rlen = l - llen;
min_ans = max(min_ans, min(llen, rlen));
max_ans = max(max_ans, max(llen, rlen));
}
fout << min_ans << ' ' << max_ans << endl;
//system("pause");
return 0;
}