Files
python/GESP/Level6/20241202.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

55 lines
2.0 KiB
C++
Raw Permalink 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;
typedef long long LL;
const int N = 1e5 + 10;
int n; // 运输站点数量
int m; // 货车数量
int x; // 两市距离
struct Node { // 运输点
int p; // 运输站点的位置
int c; // 最多容纳车辆数
} q[N];
bool cmp(Node x, Node y) { // 按到A市的距离从小到大排序
return x.p < y.p;
}
vector<int> na, nb; // 需要去靠近A市的车和靠近B市的车
LL ans; // 里程合计
int main() {
cin >> n >> m >> x;
for (int i = 1; i <= n; i++)
cin >> q[i].p >> q[i].c;
sort(q + 1, q + n + 1, cmp); // 按距离A市的距离将运输点排序
for (int i = 1; i <= m; i++) { // 枚举每个货车
int a, b;
cin >> a >> b;
if (a >= b) // 到A市次数不低于到B市次数
na.push_back(a - b); // 只记录A市超过B市的次数
else // 到A市次数低于到B市次数
nb.push_back(b - a); // 只记录B市超过A市的次数
ans += 2ll * min(a, b) * x; // 相等的部分计算距离
}
sort(na.begin(), na.end(), greater<int>()); // 按去A市的次数从大到小排序
sort(nb.begin(), nb.end(), greater<int>()); // 按去B市的次数从大到小排序
int l = 1, r = n; // 最靠近A市的运输点为1最靠近B市的运输点为n
for (int i = 0; i < na.size(); i++) { // 枚举去A市的车
while (q[l].c == 0)
l++; // 没有容量就去下一个运输点
q[l].c--; // 运输点容量减一
ans += 2ll * q[l].p * na[i]; // 计算路程
}
for (int i = 0; i < nb.size(); i++) { // 枚举去B市的车
while (q[r].c == 0)
r--; // 没有容量就去下一个运输点
q[r].c--; // 运输点容量减一
ans += 2ll * (x - q[r].p) * nb[i]; // 计算路程
}
cout << ans << endl;
return 0;
}