提交时间:2024-11-17 17:06:22
运行 ID: 56957
#include<iostream> #include<algorithm> using namespace std; int max(int a, int b) { return a > b ? a : b; } int min(int a, int b) { return a < b ? a : b; } int main() { int n; int a[301] = { 0 }; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int temp = a[0]; int max1 = 0, max2 = 0; for (int j = 1; j < n - 1; j=j+2) { max1 = max(max1, a[j] - temp); temp = a[j]; } max1 = max(max1, a[n - 1] - temp); temp = a[0]; for (int j = 2; j < n - 1; j = j + 2) { max2 = max(max2, a[j] - temp); temp = a[j]; } max2 = max(max2, a[n - 1] - temp); cout << max(max1,max2); return 0; }