#include<iostream> #include<cstdio> #define maxn 400010 #define ll long long #define INF 1000000000 usingnamespacestd;
int n, a[maxn]; ll k;
int st1[maxn][21], st2[maxn][21], Log[maxn]; voidinit_st(){ Log[0] = -1; for (int i = 1; i <= n; ++i) Log[i] = Log[i >> 1] + 1; for (int j = 1; j <= 20; ++j) for (int i = 1; i + (1 << j) - 1 <= n; ++i) { st1[i][j] = min(st1[i][j - 1], st1[i + (1 << j - 1)][j - 1]); st2[i][j] = max(st2[i][j - 1], st2[i + (1 << j - 1)][j - 1]); } }
intquery_min(int l, int r){ int k = Log[r - l + 1]; return min(st1[l][k], st1[r - (1 << k) + 1][k]); }
intquery_max(int l, int r){ int k = Log[r - l + 1]; return max(st2[l][k], st2[r - (1 << k) + 1][k]); }
ll check(int x){ int j = 1; ll s = 0; for (int i = 1; i <= n; ++i) { while (j <= n && query_max(i, j) - query_min(i, j) < x) ++j; s += n - j + 1; } return s; }
intmain(){ cin >> n >> k; for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), st1[i][0] = st2[i][0] = a[i]; init_st(); ll l = 1, r = (ll) n * (n - 1) / 2, mid, ans; while (l <= r) { mid = l + r >> 1; if (check(mid) >= k) ans = mid, l = mid + 1; else r = mid - 1; } cout << ans << endl; return0; }