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.

27 lines
1.0 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n; // n个客户
int sum[N], g[N], h[N]; // 疲劳值前缀和 前i个最大值 后i个最大值
struct Node {
int s; // 距离
int b; // 疲劳
const bool operator<(const Node &W) {
return b > W.b;
}
} a[N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i].s; // 住户i到入口的距离
for (int i = 1; i <= n; i++) cin >> a[i].b; // 向i住户推销产品会积累的疲劳值
sort(a + 1, a + 1 + n); // 按疲劳由大到小排序
for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i].b; // 预算出疲劳值的前缀和
for (int i = 1; i <= n; i++) g[i] = max(g[i - 1], 2 * a[i].s); // 前i个距离最大值
for (int i = n; i >= 1; i--) h[i] = max(h[i + 1], 2 * a[i].s + a[i].b); // 后i个距离最大值
for (int i = 1; i <= n; i++) printf("%d\n", max(sum[i] + g[i], sum[i - 1] + h[i]));
return 0;
}