1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| #include <iostream> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; const int N = 200010; int n, k; int a[N]; bool check(int mid) { LL cnt = 0; for (int i = n / 2; i < n; ++i) if (a[i] < mid) cnt += mid - a[i]; return cnt <= k; } int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) scanf("%d", &a[i]); sort(a, a + n); int l = 0, r = 2e9; while (l < r) { int mid = (LL) l + r + 1 >> 1; if (check(mid)) l = mid; else r = mid - 1; } printf("%d\n", r); return 0; }
|