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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define rep(i, l, r) for (int i = (l); i <= (r); ++i) #define per(i, l, r) for (int i = (l); i >= (r); --i) using std::cerr; using std::cin; using std::cout; using std::endl; using std::make_pair; using std::pair; typedef pair<int, int> pii; typedef long long ll; typedef unsigned int ui;
const int N = 100100;
ll a[N];
ll k, A, B;
ll query(ll l, ll r) { return std::upper_bound(a, a + k, r) - std::lower_bound(a, a + k, l); }
ll solve(ll l, ll r) { if (query(l, r) == 0) return A; if (l == r) { return B * query(l, r); } else { ll sol1 = solve(l, l + (r - l + 1) / 2 - 1) + solve(l + (r - l + 1) / 2, r); ll sol2 = B * (r - l + 1) * query(l, r); return std::min(sol1, sol2); } }
int main() { std::ios::sync_with_stdio(false); cout.tie(0); ll n; cin >> n >> k >> A >> B; for (int i = 0; i < k; ++i) cin >> a[i]; std::sort(a, a + k); cout << solve(1, 1 << n); return 0; }
|