蜗牛
作者:
恒_41
,
2024-04-15 22:23:21
,
所有人可见
,
阅读 2
#include <cstring>
#include <algorithm>
#include<iostream>
using namespace std;
const int N = 100010, INF = 2e9;
int a[N],b[N], x[N];
double f[N][2];
double get(int x1, int x2) {
if (x1 < x2) return (x2 - x1) / 0.7;
else return (x1 - x2) / 1.3;
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> x[i];
for (int i = 1; i < n; i++) cin >> a[i] >> b[i + 1];
for(int i = 1; i <= n; i ++) f[i][0] = f[i][1] = INF;
f[1][0]=x[1];
for (int i = 2; i <= n; i++) {
int d = x[i] - x[i - 1];
f[i][0] = min(f[i - 1][0] + d, f[i - 1][1] + get(b[i-1],0) + d);
f[i][1] = min(f[i - 1][0] +get(0,a[i-1]), f[i - 1][1] + get(b[i - 1], a[i - 1]));
}
printf("%.2lf\n", min(f[n][0],f[n][1]+b[n]/1.3));
return 0;
}