#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 template struct Z_algorithm{ vector A; Z_algorithm(T &s){ A.resize(s.size(),0); A[0] = s.size(); int i=1,j=0; while(i struct CHT{ vector v; vector a,b; int n; long long sign; T init_value; CHT(vector &x,T iv,long long s=1){ init_value = iv; sign = s; v = x; sort(v.begin(),v.end()); int temp = distance(v.begin(),unique(v.begin(),v.end())); v.resize(temp); n=1; while(true){ if(n>=v.size())break; n<<=1; } T t = v.back(); v.resize(n,t+1); a.resize(2*n,0); b.resize(2*n,init_value); } void add(T A,T B,int start){ int now = start; while(true){ int ll = (now<<(__builtin_clz(now)-__builtin_clz(n)))-n; int rr = ll + (n>>(31-__builtin_clz(now))) -1; int m = (ll+rr)>>1; bool fl = (A*v[ll]+B)<(a[now]*v[ll]+b[now]); bool fm = (A*v[m]+B)<(a[now]*v[m]+b[now]); bool fr = (A*v[rr]+B)<(a[now]*v[rr]+b[now]); if(fl&&fr){ a[now]=A; b[now]=B; break; } if(!fl&&!fr){ break; } if(fm){ swap(A,a[now]); swap(B,b[now]); swap(fl,fr); } if(fl){ now<<=1; } else{ now<<=1; now++; } } } void add_line(T A,T B){ A *= sign; B *= sign; add(A,B,1); } void add_segment(T A,T B,T L,T R){ L = distance(v.begin(),lower_bound(v.begin(),v.end(),L)); R = distance(v.begin(),lower_bound(v.begin(),v.end(),R)); if(R==L)return; L+=n; R+=n; while(true){ if(L&1){ add(A,B,L++); } if(R&1){ add(A,B,--R); } if(L>=R)break; L>>=1;R>>=1; } } T query(T x){ int now = n + distance(v.begin(),lower_bound(v.begin(),v.end(),x)); T ret = init_value; while(true){ ret = min(ret,(a[now]*x+b[now])); now>>=1; if(now<=0)break; } return ret*sign; } void show(){ int n = 1; for(int i=1;i>N>>M; vector a(N); rep(i,N)cin>>a[i]; a.push_back(-1); rep(i,M){ int t; cin>>t; a.push_back(t); } Z_algorithm> Z(a); vector c(M); rep(i,M)cin>>c[i]; vector dp(M+1,Inf64); vector t(M+5); rep(i,M+5)t[i] = i; CHT C(t,Inf64); rep(i,M+1){ if(i==0)dp[i] = 0; else{ //cout<=Inf64)ans = -1; cout<