哪位好人来救救孩子……
# include <bits/stdc++.h>
# define int long long
# define endl '\n'
# define str string
# define fst ios::sync_with_stdio (0); cin.tie (0); cout.tie (0);
using namespace std;
const int N = 1e6 + 5, M = 2e6 + 5;
const int P = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int LNF = 0x3f3f3f3f3f3f3f3f;
int n, k;
int a[N];
int maxn;
int l, r, mid;
int ans;
bool check (int x) {
if (! x) {
return 1;
}
int cnt = 0;
int sum = 0;
int j = 1;
int use;
for (int i = 1; i <= x; i ++ ) {
while ((j <= n) && (a[j] <= i)) {
sum += a[j];
cnt ++;
j ++;
}
use = (((cnt * (i + 1))) - sum);
if (use > (i * k)) {
return 0;
}
}
return 1;
}
signed main () {
fst;
cin >> n >> k;
for (int i = 1; i <= n; i ++ ) {
cin >> a[i];
maxn = max (maxn, a[i]);
}
sort (a + 1, a + 1 + n);
r = (maxn + maxn + n);
while (l <= r) {
mid = ((l + r) / 2);
if (check (mid)) {
ans = mid;
l = (mid + 1);
}
else {
r = (mid - 1);
}
}
cout << ans;
return 0;
}