题意:https://codeforces.com/contest/1016/problem/C
思路:首先很容易发现我们对于每一列的出轨点固定,然后就是出轨点两侧有且只有唯一走法,那么我们只需要预处理两种走法,然后枚举拐点即可。左边的预处理显然很简单,难点在于右边的预处理。我们如果不考虑前面的拐弯的影响的话,那么其实后面的只是一个片段,所以我们可以预处理两种从上到下和从下到上,然后截取片段即可,然后考虑影响,影响就是拐弯次数乘上后面的总数和。
/*keep on going and never give up*/
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
#define int long long
typedef pair<int, int> pii;
#define lowbit(x) x&(-x)
#define endl '\n'
#define wk is zqx ta die
int a[300006];
int b[300006];
int sum[300006];
int suma[300006];
int sumb[300006];
int sumc[300006];
int n;
void ini() {
for (int i = n; i >= 1; i--) {
sum[i] = sum[i + 1] + b[i] + a[i];
}
for (int i = n, j = n; i >= 1; i--, j++) {
suma[i] = suma[i + 1] + (i - 1) * a[i] + j * b[i];
}
for (int i = n, j = n; i >= 1; i--, j++) {
sumb[i] = sumb[i + 1] + (i - 1) * b[i] + j * a[i];
}
int tot = 0;
for (int i = 1; i <= n; i++) {
if (i & 1) {
sumc[i] = sumc[i - 1] + tot * a[i] + (tot + 1) * b[i];
tot += 2;
} else {
sumc[i] = sumc[i - 1] + tot * b[i] + (tot + 1) * a[i];
tot += 2;
}
}
}
signed main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
ini();
int ans = 0;
for (int i = 1; i <= n; i++) {
if (i & 1) {
ans = max(ans, sumc[i - 1] + suma[i] + (i - 1) * sum[i]);
} else {
ans = max(ans, sumc[i - 1] + sumb[i] + (i - 1) * sum[i]);
}
}
cout << ans << endl;
return 0;
}