A bit Greedy can achieve O(m) - the mid station between 2 adjacent cities has the longest distance within that range.
#include <vector> #include <iostream> using namespace std; int main(){ int n; int m; cin >> n >> m; vector<int> c(m); for(int c_i = 0;c_i < m;c_i++){ cin >> c[c_i]; } sort(c.begin(), c.end()); int r = 0; for(int i =0; i < m - 1; i ++) { r = max(r, (c[i + 1] - c[i])/2); } r = max(r, c[0]); r = max(r, n - c.back() - 1); cout << r << endl; return 0; }
时间: 2024-11-05 19:02:09