/* -*- coding: utf-8 -*- * * 1739.cc: No.1739 Princess vs. Dragoness (& AoE) - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ typedef long long ll; /* global variables */ int hs[MAX_N]; /* subroutines */ bool check(int n, int a, int b, int x, int y, int k) { priority_queue q; for (int i = 0; i < n; i++) if (hs[i] > k) q.push(hs[i] - k); while (a > 0 && ! q.empty()) { int h = q.top(); q.pop(); if (h >= x) { int d = min(a, h / x); h -= d * x, a -= d; } else h -= x, a--; if (h > 0) q.push(h); } ll sum = 0; while (! q.empty()) sum += q.top(), q.pop(); return (sum <= (ll)y * b); } /* main */ int main() { int n, a, b, x, y; scanf("%d%d%d%d%d", &n, &a, &b, &x, &y); for (int i = 0; i < n; i++) scanf("%d", hs + i); int k0 = -1, k1 = *max_element(hs, hs + n); while (k0 + 1 < k1) { int k = (k0 + k1) / 2; if (check(n, a, b, x, y, k)) k1 = k; else k0 = k; } printf("%d\n", k1); return 0; }