#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<map> #include<set> #include<queue> #include<stack> #include<cctype> usingnamespace std; longlong a[100005], b[100005], p[100005], n, k, m; longlong sum[100005]; //仅在C函数中用到,sum[p[i]]表示值与a[i]相等的元素出现过的次数 boolC(longlong x) { int head = 1, end; //滑动窗格的起点和终点
longlong ret = 0; //值大于x的元素个数
for (int i = 1; i <= n; i++) sum[i] = 0; //初始化
for (end = 1; end <= n; end++) { sum[p[end]]++; //值为a[end]的数多了一个
while (sum[p[end]] >= x) //如果当前滑动窗格满足条件就一直缩小滑动窗格 { ret += n - end + 1; //把滑动窗格的起点往右移 sum[p[head]]--; head++; } }
return ret >= k; } intmain() { scanf("%d%d", &n, &k); int i; for (i = 1; i <= n; i++) { scanf("%lld", &a[i]); b[i] = a[i]; } sort(b + 1, b + 1 + n); m = unique(b + 1, b + 1 + n) - b - 1; for (i = 1; i <= n; i++) p[i] = lower_bound(b + 1, b + 1 + m, a[i]) - b; longlong l = 1, r = n + 1, m; while (r - l > 1) { m = ((l + r) >> 1); if (C(m)) l = m; else r = m; } printf("%lld", l); return0; }