#include //#include using namespace std; //using namespace atcoder; using ll = long long; //using mint = modint998244353; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); /* dp(i, j, k) = 左の家にi個、右の家にj個行って、左(k=0),右(k=1)にいる時の最小値 */ ll N, S, sm=0; cin >> N >> S; vector X(N), W(N); for (int i=0; i> X[i]; X[i] -= S; } for (int i=0; i> W[i]; sm += W[i]; } vector nx, px(1, 0), nw, pw(1, 0), ns(1, 0), ps(1, 0); for (int i=0; i(2, 1e18))); dp[0][0][0] = 0; dp[0][0][1] = 0; auto chmin=[&](ll &x, const ll &y)->void{ if (x > y) x = y; }; for (int i=0; i右 if (j != NP-1){ dis = nx[i]+px[j+1]; chmin(dp[i][j+1][1], dp[i][j][0]+dis*wei); } //右->右 if (j != NP-1){ dis = px[j+1]-px[j]; chmin(dp[i][j+1][1], dp[i][j][1]+dis*wei); } //右->左 if (i != NN-1){ dis = nx[i+1]+px[j]; chmin(dp[i+1][j][0], dp[i][j][1]+dis*wei); } //左->左 if (i != NN-1){ dis = nx[i+1]-nx[i]; chmin(dp[i+1][j][0], dp[i][j][0]+dis*wei); } } } cout << min(dp[NN-1][NP-1][0], dp[NN-1][NP-1][1]) << endl; return 0; }