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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rd scanf
#define pt printf
#define setp(x) setprecision(x)
#define mem(x,y) memset(x,y,sizeof(x))
#define sz(x) (int)x.size()
#define umn(x,y) x=min(x,y)
#define umx(x,y) x=max(x,y)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
const double eps=1e-9;
const ll INF=1e18;
const ll P=998244353;
const ll MXN=1e5+5;
inline ll mod(ll x){return x>=P?x-P:x;}
inline ll mul(ll x,ll y){if(x<y)swap(x,y);ll res=0;while(y){if(y&1)res=mod(res+x);x=mod(x<<1);y>>=1;}return res;}
inline ll qpow(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%P;x=x*x%P;y>>=1;}return res;}
ll gcd(ll x,ll y){return !y?x:gcd(y,x%y);}
inline void pbin(ll x,ll y){for(;~y;y--)cerr<<char('0'+((x>>y)&1));cerr<<endl;}
ll n,a,b,s;
ll arr[MXN];
inline ll cal(ll add){
ll last=0,ans=0;
for(int i=1;i<=n;i++){
last=max(last,0ll)+arr[i]+add;
umx(ans,last);
}
return ans;
}
inline bool chk(ll add,ll pwr){
ll tmp=cal(add);
for(int i=0;i<=pwr;i++)
if((tmp<<i)>=s)return 1;
return 0;
}
inline void solve(){
//codes
cin>>n>>a>>b>>s;
for(int i=1;i<=n;i++)cin>>arr[i];
ll ans=INF;
for(int i=0;i<=32;i++){
ll l=0,r=2e9;
while(l<r){
ll mid=(l+r)>>1;
if(chk(mid,i))r=mid;
else l=mid+1;
}
ans=min(ans,a*l+b*i);
}
cout<<ans;
}
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
ios_base::sync_with_stdio(0);cin.tie(0);
cout<<setiosflags(ios::fixed);
srand(time(NULL));
solve();
return 0;
}
|