Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define MOD 1000000007
- using namespace std;
- const int inf = 1e9;
- void solve() {
- int N; cin >> N;
- vector<int> A(N);
- for(int i = 0; i < N; i++) {
- cin >> A[i];
- }
- sort(A.begin(), A.end());
- int ans = inf;
- for(int i = 1; i < N - 1; i++) {
- ans = min(ans, A[i + 1] - A[i - 1]);
- }
- cout << ans << '\n';
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- #ifdef LOCAL
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int test_cases = 1;
- cin >> test_cases;
- for(int test_case = 1; test_case <= test_cases; test_case++) {
- // cout << "Case #" << test_case << ": ";
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement