#include #include #include /** One chatbot's sulky response to the prompt to improve its over-complex solution: That seems much too complicated. Can't the solution simply iterate over every item to remove, and check the distances between its predecessor and successor, then take the minimum of all that? This should be a very short program for an easy task! **/ int main(){ // Fast I/O std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n; std::cin >> n; std::vector s(n); for (int i = 0; i < n; ++i) { std::cin >> s[i]; } // This program is CORRECT but TOO SLOW for the contest long long overall_best_max = -1; for (int i = 1; i < n - 1; ++i) { // For each stop to remove... // 1. Figure out the new set of legs std::vector current_legs; for (int j = 0; j < n - 1; ++j) { if (j == i - 1) { // This is the point of the merge current_legs.push_back(s[j + 2] - s[j]); } else if (j == i) { // This leg was merged away, skip it continue; } else { // This leg is unchanged current_legs.push_back(s[j + 1] - s[j]); } } // 2. Find the longest leg in this new itinerary long long current_max = 0; for(long long leg : current_legs) { if (leg > current_max) { current_max = leg; } } // 3. See if this is the best max we've found so far if (overall_best_max == -1 || current_max < overall_best_max) { overall_best_max = current_max; } } std::cout << overall_best_max << std::endl; }