代码是这样的:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
pair<int, int> evacuateBridge(int L, int N, vector<int>& positions) {
if (N == 0) {
return {0, 0};
}
sort(positions.begin(), positions.end());
int minTime = max(positions[0], L + 1 - positions[N-1]);
int maxTime = max(L + 1 - positions[0], positions[N-1]);
return {minTime, maxTime};
}
int main() {
int L, N;
cin >> L >> N;
vector<int> positions(N);
for (int i = 0; i < N; ++i) {
cin >> positions[i];
}
pair<int, int> result = evacuateBridge(L, N, positions);
cout << result.first << " " << result.second << endl;
return 0;
}