Advertisement
Guest User

https://codeforces.com/contest/1734/problem/A

a guest
Sep 24th, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define MOD 1000000007
  4. using namespace std;
  5.  
  6. const int inf = 1e9;
  7.  
  8. void solve() {
  9.     int N; cin >> N;
  10.     vector<int> A(N);
  11.     for(int i = 0; i < N; i++) {
  12.         cin >> A[i];
  13.     }
  14.     sort(A.begin(), A.end());
  15.     int ans = inf;
  16.     for(int i = 1; i < N - 1; i++) {
  17.         ans = min(ans, A[i + 1] - A[i - 1]);
  18.     }
  19.     cout << ans << '\n';
  20. }
  21.  
  22. int main() {
  23.     ios::sync_with_stdio(0);
  24.     cin.tie(0);
  25. #ifdef LOCAL
  26.     freopen("input.txt", "r", stdin);
  27.     freopen("output.txt", "w", stdout);
  28. #endif
  29.     int test_cases = 1;
  30.     cin >> test_cases;
  31.     for(int test_case = 1; test_case <= test_cases; test_case++) {
  32.         // cout << "Case #" << test_case << ": ";
  33.         solve();
  34.     }
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement