Files
python/TangDou/CSP-J/AcWingTraining/absolute/path/to/file.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

44 lines
1.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
struct Node {
int s; // 距离
int b; // 疲劳值
bool operator<(const Node &W) const {
return b > W.b; // 按疲劳值从大到小排序
}
} a[N];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i].s;
for (int i = 1; i <= n; i++) cin >> a[i].b;
sort(a + 1, a + 1 + n);
for (int x = 1; x <= n; x++) {
int max_dist = 0;
int total_fatigue = 0;
int max_alternative = 0;
// 计算前x个住户的总疲劳值和最大距离
for (int i = 1; i <= x; i++) {
total_fatigue += a[i].b;
if (2 * a[i].s > max_dist) {
max_dist = 2 * a[i].s;
}
// 计算替代方案:前x-1个疲劳值 + 第i个的距离*2+疲劳值
int alternative = total_fatigue - a[i].b + 2 * a[i].s + a[i].b;
if (alternative > max_alternative) {
max_alternative = alternative;
}
}
int max_fatigue = max(total_fatigue + max_dist, max_alternative);
cout << max_fatigue << endl;
}
return 0;
}