| 比赛 |
NOIP2025模拟赛4 |
评测结果 |
AAAAAAAAAAAAAAAA |
| 题目名称 |
Lunch Concert |
最终得分 |
100 |
| 用户昵称 |
wdsjl |
运行时间 |
1.429 s |
| 代码语言 |
C++ |
内存使用 |
10.65 MiB |
| 提交时间 |
2025-11-27 11:32:48 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int N = 4e6 + 10;
int n, m;
i64 lsh[N], p[N], w[N], d[N], a[N], b[N], ans;
void add(int l, int r, i64 x, i64 y) {
a[l] += x;
a[r + 1] -= x;
b[l] += y;
b[r + 1] -= y;
}
signed main() {
freopen("Concert.in", "r", stdin);
freopen("Concert.out", "w", stdout);
scanf("%lld", &n);
for (int i = 0; i < n; ++i) {
scanf("%lld%lld%lld", &p[i], &w[i], &d[i]);
lsh[m++] = p[i] - d[i];
lsh[m++] = p[i] + d[i];
}
sort(lsh, lsh + m);
m = unique(lsh, lsh + m) - lsh;
for (int i = 0; i < n; ++i) {
i64 x = p[i] - d[i];
add(0, lower_bound(lsh, lsh + m, x) - lsh, -w[i], w[i] * x);
x = p[i] + d[i];
add(upper_bound(lsh, lsh + m, x) - lsh, m, w[i], -w[i] * x);
}
ans = a[0] * lsh[0] + b[0];
for (int i = 1; i <= m; ++i) {
a[i] += a[i - 1];
b[i] += b[i - 1];
if (a[i] < 0) {
ans = min(ans, a[i] * lsh[i] + b[i]);
} else {
ans = min(ans, a[i] * lsh[i - 1] + b[i]);
}
}
printf("%lld", ans);
return 0;
}