26 lines
589 B
C++
26 lines
589 B
C++
#include <iostream>
|
|
#define N 100010
|
|
#define ll long long
|
|
using namespace std;
|
|
int n;
|
|
ll d, v[N], p[N], ans;
|
|
int main() {
|
|
cin >> n >> d;
|
|
for (int i = 1; i < n; i++) cin >> v[i];
|
|
for (int i = 1; i <= n; i++) cin >> p[i];
|
|
int now = 1, nxt = 2;
|
|
ll tank = 0;
|
|
while (now < n) {
|
|
ll dis = v[now];
|
|
while (nxt < n && p[nxt] >= p[now])
|
|
dis += v[nxt++];
|
|
int cnt = 0;
|
|
while (tank + cnt * d < dis) cnt++;
|
|
ans += p[now] * cnt;
|
|
tank += cnt * d - dis;
|
|
now = nxt++;
|
|
}
|
|
cout << ans << endl;
|
|
return 0;
|
|
}
|