#include #include #include using namespace std; typedef long long lint; typedef vectorvi; typedef pairpii; #define rep(i,n)for(int i=0;i<(int)(n);++i) struct MinBIT { static const int SIZE = 1 << 17; static const int INFINITY = (1 << 30) - 1; int bit[SIZE]; MinBIT() { rep(i,SIZE)bit[i]=INFINITY; } void update(int x, int value) { while(x0){ y=min(y,bit[x]); x&=x-1; } return y; } }; int a[300001],x[300001],y[300001]; int dp[300001]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n; cin>>n; rep(i,n)cin>>a[i]; rep(i,n)cin>>x[i]; rep(i,n)cin>>y[i]; MinBIT m1; MinBIT p1; rep(i,n){ // update m1.update(100001-x[i],x[i]+y[i]+dp[i]); p1.update(1+x[i],-x[i]+y[i]+dp[i]); // query int ans=1e9; int curA=a[i]; ans=min(ans,m1.query(100001-curA)-curA); ans=min(ans,p1.query(curA+1)+curA); dp[i+1]=ans; } cout<