#include #include #include using namespace std; int max_dist(vector &a, const int d) { const int n = a.size(); sort(a.begin(), a.end()); int l = 0; int max_d = 0; for (int r = 1; r < n; r++) { while (a[r] - a[l] > d) { l++; } int curr_d = a[r] - a[l]; if (max_d < curr_d) { max_d = curr_d; } } return max_d; } int main(void) { int n; cin >> n; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int d; cin >> d; cout << max_dist(a, d) << endl; return 0; }