题目链接:http://codeforces.com/contest/1111/problem/C
#include<bits/stdc++.h>
using namespace std;#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<ll,ll>
#define mk(x,y) make_pair(x,y)
const int maxn=1e5+8;
const int ub=1e6;
ll A,B;
int n,k;
ll h[maxn];
ll tmp[31];
/*
题目意思不再描述,感觉如果不是空间限制就是个线段树的题目,
但是空间开不了这么大,一种做法是动态开点,
还有一种就是分治处理,分治的样子和线段树差不多,
详见代码。
*/ll f(int nn,int s,int t,ll add){if(nn==0){int pos1=lower_bound(h,h+k,h[s])-h;int pos2=upper_bound(h,h+k,h[s])-h;return 1LL*(pos2-pos1)*B;}int pos=upper_bound(h+s,h+t,tmp[nn-1]+add)-h-s;//////while(pos+1<t&&h[pos]==h[pos+1]) pos++;if(pos==t-s){ll val=f(nn-1,s,t,add)+A;val=min(val,1LL*(t-s)*B*tmp[nn]);return val;}else if(pos==0){ll val=f(nn-1,s,t,add+tmp[nn-1])+A;val=min(val,1LL*(t-s)*B*tmp[nn]);return val;}else return min(1LL*(t-s)*B*tmp[nn],f(nn-1,s,s+pos,add)+f(nn-1,s+pos,t,add+tmp[nn-1]));
}int main(){mst(h,0);tmp[0]=1LL;rep(i,1,31) tmp[i]=tmp[i-1]*2LL;cin>>n>>k>>A>>B;rep(i,0,k) cin>>h[i];sort(h,h+k);///if(k==0) cout<<A<<'\n';else cout<<f(n,0,k,0LL)<<'\n';return 0;
}