Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
- #define NeedForSpeed \
- ios_base::sync_with_stdio(false); \
- cin.tie(NULL); \
- cout.tie(NULL);
- #define int long long
- #define all(x) (x).begin(), (x).end()
- typedef vector<int> vi;
- typedef vector<bool> vb;
- typedef vector<vi> vvi;
- typedef vector<pair<int, int>> vpi;
- #define f first
- #define s second
- #define endl "\n"
- const int mod = 1000000007;
- int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
- void solve()
- {
- int n;
- cin >> n;
- vi v(n);
- for (int i = 0; i < n; i++)
- {
- cin >> v[i];
- }
- sort(all(v));
- if (n == 1)
- {
- cout << 1 << endl;
- return;
- }
- if (n == 1)
- {
- cout << abs(v[1] - v[0]) << endl;
- return;
- }
- if ((n % 2) == 0)
- {
- // only 1 answer is possible
- int ans = 0;
- for (int i = 0; i < n; i += 2)
- {
- ans = max(ans, (v[i + 1] - v[i]));
- }
- cout << ans << endl;
- }
- else
- {
- // leave 1 element and do the same, as we can get a number closed to it
- int ans = 1e18;
- for (int i = 0; i < n; i += 2)
- {
- int ma1 = 0, ma2 = 0;
- for (int j = 0; j < i; j += 2)
- {
- ma1 = max(ma1, v[j + 1] - v[j]);
- }
- for (int j = i + 1; j < n; j += 2)
- {
- ma2 = max(ma2, v[j + 1] - v[j]);
- }
- ans = min(ans, max(ma1, ma2));
- }
- cout << ans << endl;
- }
- return;
- }
- signed main()
- {
- NeedForSpeed;
- int t = 1;
- cin >> t;
- while (t--)
- {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement