HTML & JS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define le length()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (__typeof(n) i = 0; i < n; i++)
#define repo(i, n) for (__typeof(n) i = 1; i <= n; i++)
#define fastIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define eps 1e-6
#define pi 3.141592653589793
#define c(a) cout << a << "\n";
#define ao(a)        \
    for (auto i : a) \
        cout << i << " ";
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int main()
{
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];
    set<ll> s;
    s.insert(a[0]);
    ll ans = 1e18;
    for (int i = 1; i < n; i++)
    {
        auto it = s.upper_bound(a[i]);
        if (it != s.end() && *it>a[i])
            ans = min(ans, *it - a[i]);
        s.insert(a[i]);
    }
    c(ans) return 0;
}

Generated URL:

Runtime Errors:

Bad memory access (SIGBUS)

Output:

No Output
Report Bug