Advertisement
sherry_ahmos

Untitled

Mar 26th, 2023
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <string.h>
  5. #include <math.h>
  6. #include <set>
  7. #include <stack>
  8. #include <queue>
  9. #include <bits/stdc++.h>
  10.  
  11. using namespace std;
  12.  
  13. #define ll long long
  14. #define cy cout << "YES\n"
  15. #define cn cout << "NO\n"
  16. #define nl "\n"
  17. #define fi first
  18. #define se second
  19. #define MOD 1000000007
  20. #define all(v) v.begin(), v.end()
  21. #define rall(v) v.end(), v.begin()
  22.  
  23. #define sz(s) s.size()
  24. #define f0r(j, n) for (ll i = j; i < n; i++)
  25. template <typename T = int>
  26. istream &operator>>(istream &in, vector<T> &v)
  27. {
  28.     for (auto &x : v)
  29.         in >> x;
  30.     return in;
  31. }
  32.  
  33. template <typename T = int>
  34. ostream &operator<<(ostream &out, const vector<T> &v)
  35. {
  36.     for (const T &x : v)
  37.         out << x << " ";
  38.     return out;
  39. }
  40.  
  41. void sherry()
  42. {
  43.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  44. #ifndef ONLINE_JUDGE
  45.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  46. #endif
  47. }
  48. /*
  49. int gcd(ll a, ll b)
  50. {
  51.     if (b == 0)
  52.         return a;
  53.     return (b, a % b);
  54. }
  55. */
  56.  
  57. void solve()
  58. {
  59.     int n;
  60.     cin >> n;
  61.     vector<int> v(n);
  62.     cin >> v;
  63.     set<int> st;
  64.     sort(all(v));
  65.     for (int i = 0; i < n - 1; i++)
  66.     {
  67.         st.insert(v[i + 1] - v[i]);
  68.         if (i + 2 < n)
  69.             st.insert(v[i + 2] - v[i]);
  70.     }
  71.     int i = 0;
  72.     for (auto &x : st)
  73.     {
  74.         i++;
  75.         if (i == 3)
  76.         {
  77.             cout << x << nl;
  78.             return;
  79.         }
  80.     }
  81. }
  82. int main()
  83. {
  84.     sherry();
  85.     int t = 1;
  86.     // cin >> t;
  87.     while (t--)
  88.         solve();
  89.     return 0;
  90. }
  91. // 5 1 0 3 4 2
  92. // 2 5 5 6 7
  93. // 3 1 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement