P9749 [CSP-J 2023] 公路题解(%100数据)
#include <bits/stdc++.h>
using namespace std;
long long c[100005] = {0}, d[100005] = {0};
int main() {
long long a = 0, b = 0, g = 0;
cin >> a >> b;
for (long long i = 0; i < a - 1; i++) {
cin >> c[i];
}
for (long long i = 0; i < a; i++) {
cin >> d[i];
}
long long i = 0, last = 0;
while (i != a - 1) {
long long j = i + 1, len = 0;
len += c[i];
while (j < a - 1 && d[j] >= d[i]) {
len += c[j];
j++;
}
len -= last;
long long x = len / b;
if (len % b != 0) {
x++;
}
g += x * d[i];
last = x * b - len;
i = j;
}
cout << g;
}