You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
#define int long long
|
|
|
|
|
const int N = 100010;
|
|
|
|
|
|
|
|
|
|
int v[N]; // 站点间的距离
|
|
|
|
|
int a[N]; // 每个站点的油价
|
|
|
|
|
int n; // n个站点
|
|
|
|
|
double d; // 1升油可以跑多少公里
|
|
|
|
|
int money; // 一共花费
|
|
|
|
|
int r; // 油箱的油可以跑的公里数
|
|
|
|
|
/*
|
|
|
|
|
5 4
|
|
|
|
|
10 10 10 10
|
|
|
|
|
9 8 9 6 5
|
|
|
|
|
|
|
|
|
|
答案:79
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
int getMoney(int begin, int end) { // 左闭右开
|
|
|
|
|
int length = 0;
|
|
|
|
|
for (int i = begin; i < end; i++) length += v[i];
|
|
|
|
|
|
|
|
|
|
if (r >= length) {
|
|
|
|
|
// 不用加油
|
|
|
|
|
r -= length;
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
// 需要加油, 计算加多少油: 油箱的油还有剩余,还能跑几公里
|
|
|
|
|
int add = ceil((length - r) / d);
|
|
|
|
|
// 计算加油费用
|
|
|
|
|
int x = a[begin] * add;
|
|
|
|
|
// 跑到 end, 油箱的油还能跑几公里
|
|
|
|
|
r = add * d + r - length;
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
signed main() {
|
|
|
|
|
cin >> n >> d; // n个站点,每升油可以让车前进d公里
|
|
|
|
|
for (int i = 1; i < n; i++) cin >> v[i]; // 站点间的距离 a1~a2,a2~a3,...
|
|
|
|
|
for (int i = 1; i <= n; i++) cin >> a[i]; // 不同站点加油的价格
|
|
|
|
|
|
|
|
|
|
int i = 1;
|
|
|
|
|
while (i < n) {
|
|
|
|
|
int j = i + 1;
|
|
|
|
|
// 找到下一个便宜的加油站
|
|
|
|
|
while (j <= n && a[j] >= a[i]) j++;
|
|
|
|
|
money += getMoney(i, j);
|
|
|
|
|
i = j;
|
|
|
|
|
}
|
|
|
|
|
cout << money << endl;
|
|
|
|
|
}
|