#pragma region template // clang-format off #ifdef ONLINE_JUDGE #pragma GCC optimize "fast-math" #endif #ifdef LOCAL_NDEBUG #include #endif // #define USE_EXTERNAL_CONTAINERS // #define NO_PRINT_INF #ifdef USE_EXTERNAL_CONTAINERS #define PROPER #include #include #include #include template using tree = __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; template using hash_table = __gnu_pbds::gp_hash_table; #endif #ifdef LOCAL_DEBUG #if (defined USE_EXTERNAL_CONTAINERS) || (defined NO_PRINT_INF) #include <../src/debugger.hpp> #else #include #endif #endif // #define PROPER #define _USE_MATH_DEFINES #if (defined __INTELLISENSE__) && (!defined PROPER) #define NDEBUG namespace std { #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if (defined __INTELLISENSE__) && (!defined PROPER) using namespace std; } #endif using namespace std::literals; #ifdef LOCAL_DEBUG #define CP_LIBRARY_DEBUG_LEVEL 2 #define STR(x) #x #define STRINGIFY(x) STR(x) #define FILE_LINE "[Debug] ./" __FILE__ ":" STRINGIFY(__LINE__) #define see(...) debugger::multi_print(#__VA_ARGS__, __VA_ARGS__) #define see2(arg) arg.debug_print(#arg) #define here(...) debugger::os << FILE_LINE << " in " << __func__ << ": \033[32mReached\033[39m\n" #define com(msg) debugger::os << FILE_LINE << " in " << __func__ << ":\n \033[36mComment:\033[39m " << msg << "\n" #define err(msg) debugger::os << FILE_LINE << " in " << __func__ << ":\n \033[31mError:\033[39m " << msg << "\n" #define local(...) do { __VA_ARGS__ } while (0) #define alter(x, y) x #define pass (com("ToDo: Fill here"), true) #else #define see(...) (static_cast(0)) #define see2(arg) (static_cast(0)) #define here(...) (static_cast(0)) #define com(msg) (static_cast(0)) #define err(msg) (static_cast(0)) #define local(...) (static_cast(0)) #define alter(x, y) y #ifdef __INTELLISENSE__ #define pass (static_cast(0)) #else #define pass static_assert(false) #endif #endif #if (defined LOCAL_DEBUG) && (!defined NOWARN) #define warn(msg) debugger::os << FILE_LINE << " in " << __func__ << ":\n \033[33mWarning:\033[39m " << msg << "\n" #else #define warn(msg) (static_cast(0)) #endif #if (defined LOCAL_DEBUG) || (defined LOCAL_NDEBUG) || (defined __INTELLISENSE__) #define NOEXCEPT #define M_assert(expr) assert(expr) #define O_assert(expr) assert(expr) #else #define NOEXCEPT noexcept #define M_assert(expr) do {if(__builtin_expect(!(expr), 0)) {auto p = static_cast(std::malloc(1 << 30)); for (int i = 0; i < (1 << 27); p[i] = 1, i += (1 << 9)); std::cerr << (*p);}} while (0) #define O_assert(expr) do {if(__builtin_expect(!(expr), 0)) {const auto X = std::string(1000, '-'); for(int i = 0; i < (1 << 18); i++) std::cout << X;}} while (0) #endif #define CP_LIBRARY_WARN(msg) warn(msg) #define CP_LIBRARY_ASSERT(...) O_assert(__VA_ARGS__) #define as(type, val) static_cast>(val) #define INDIRECT(...) __VA_ARGS__ #define rep(loop_var, loop_end) \ for ( \ auto loop_var = as(std::make_signed_t, 0); \ loop_var < as(decltype(loop_var), loop_end); \ ++loop_var \ ) #define rng(loop_var, loop_start, loop_end, loop_increment) \ for ( \ auto loop_var = as(INDIRECT(std::make_signed_t>), loop_start); \ ((loop_increment) > 0) ? (loop_var < as(decltype(loop_var), loop_end)) : (loop_var > as(decltype(loop_var), loop_end)); \ loop_var += (loop_increment) \ ) #define erng(loop_var, loop_start, loop_end, loop_increment) \ for ( \ auto loop_var = as(INDIRECT(std::make_signed_t>), loop_start); \ ((loop_increment) > 0) ? (loop_var <= as(decltype(loop_var), loop_end)) : (loop_var >= as(decltype(loop_var), loop_end)); \ loop_var += (loop_increment) \ ) [[maybe_unused]] constexpr int INF = 1000000005; [[maybe_unused]] constexpr long long LINF = 1000000000000000005LL; [[maybe_unused]] constexpr double EPS = 1e-9; [[maybe_unused]] constexpr long double LEPS = 1e-14L; [[maybe_unused]] constexpr int dy[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0}; [[maybe_unused]] constexpr int dx[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0}; template [[nodiscard]] constexpr auto Min(const Ts... args) { return std::min({ as(std::common_type_t, args) ... }); } template [[nodiscard]] constexpr auto Max(const Ts... args) { return std::max({ as(std::common_type_t, args) ... }); } // clang-format on #pragma endregion //! @file binary_search.hpp #ifndef CP_LIBRARY_BINARY_SEARCH_HPP # define CP_LIBRARY_BINARY_SEARCH_HPP # include # include # include # ifndef CP_LIBRARY_ASSERT //! @brief Assert macro # define CP_LIBRARY_ASSERT(...) assert(__VA_ARGS__) # define CP_LIBRARY_ASSERT_NOT_DEFINED # endif namespace lib { //! @brief Find the minimum or maximum value that satisfies the condition. //! @tparam Tp Return type (deduced from parameters) //! @tparam Func callable type (function reference, class with operator(), ...) //! @param ok Initial value for which the condition is satisfied //! @param ng Initial value for which the condition is not satisfied //! @param f Callable object that takes 1 parameter of Tp and returns bool indicating if the condition is satisfied //! @param diff Difference (end condition of binary search). 1 for integers, small value (e.g. 1e-9) for real numbers //! @return minimum value (if ok < ng) or maximum value (if ok > ng) //! @note One and only one boundary value between ok and ng must exist. //! @note Time complexity: O(log(|ok - ng|)) template [[nodiscard]] Tp binary_search(Tp ok, Tp ng, const Func& f, const Tp diff = 1) { static_assert(std::is_same_v()(std::declval())), bool>); CP_LIBRARY_ASSERT(f(ok)); CP_LIBRARY_ASSERT(!f(ng)); if (ok < ng) while (ng - ok > diff) { const Tp mid = ok + (ng - ok) / 2; (f(mid) ? ok : ng) = mid; } else while (ok - ng > diff) { const Tp mid = ng + (ok - ng) / 2; (f(mid) ? ok : ng) = mid; } return ok; } } // namespace lib # ifdef CP_LIBRARY_ASSERT_NOT_DEFINED # undef CP_LIBRARY_ASSERT # undef CP_LIBRARY_ASSERT_NOT_DEFINED # endif #endif // CP_LIBRARY_BINARY_SEARCH_HPP long long N, A, B, X, Y; std::vector H; bool check(long long K) { std::vector HH = H; long long AA = A; for (auto&& x : HH) { x -= K; if (x < 0) { x = 0; } } rep(i, N) { long long t = Min(AA, HH[i] / X); HH[i] -= X * t; AA -= t; if (AA == 0) { break; } } if (AA > 0) { std::sort(std::begin(HH), std::end(HH), [&](long long L, long long R) { return L % X > R % X; }); rep(i, N) { long long t = Min(AA, (HH[i] + X - 1) / X); HH[i] -= X * t; if (HH[i] < 0) { HH[i] = 0; } AA -= t; if (AA == 0) { break; } } } return std::reduce(std::cbegin(HH), std::cend(HH), 0LL) <= B * Y; } void solve() { std::cin >> N >> A >> B >> X >> Y; H.resize(N); std::copy_n(std::istream_iterator(std::cin), std::size(H), std::begin(H)); if (check(0)) { std::cout << "0\n"; return; } long long ok = INF, ng = 0; std::cout << lib::binary_search(ok, ng, check) << '\n'; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout << std::fixed << std::setprecision(25); solve(); }