'commit'
This commit is contained in:
44
TangDou/CSP-J/AcWingTraining/absolute/path/to/file.cpp
Normal file
44
TangDou/CSP-J/AcWingTraining/absolute/path/to/file.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user