| 比赛 |
NOIP2025模拟赛4 |
评测结果 |
AAAAAAAATTTTTTTT |
| 题目名称 |
Lunch Concert |
最终得分 |
50 |
| 用户昵称 |
LikableP |
运行时间 |
8.994 s |
| 代码语言 |
C++ |
内存使用 |
2.62 MiB |
| 提交时间 |
2025-11-27 09:35:24 |
显示代码纯文本
#include <cstdio>
#include <cctype>
template <typename T> T read() {
T res = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) res = (res << 3) + (res << 1) + (ch ^ 48);
return res * f;
}
void write(__int128 x, char ed = '\n') {
if (x < 0) x = -x, putchar('-');
static int sta[64], top = 0;
do {
sta[++top] = x % 10;
x /= 10;
} while (x);
while (top) {
putchar(sta[top--] ^ 48);
}
putchar(ed);
}
template <typename T> void write(T x, char ed = '\n') {
write((__int128)x, ed);
}
#include <algorithm>
typedef long long ll;
const int MAXN = 2e5 + 10;
struct People {
int pos, hear, cost;
} a[MAXN];
int n;
ll ans = 0x7fffffffffffffff;
void work(int place) {
ll sum = 0;
for (int i = 1; i <= n; ++i) {
if (abs(a[i].pos - place) <= a[i].hear) continue;
int delta = std::min(abs(a[i].pos - a[i].hear - place), abs(a[i].pos + a[i].hear - place));
sum += 1LL * delta * a[i].cost;
if (sum >= ans) return;
}
ans = sum;
}
int main() {
#ifdef LOCAL
freopen("!input.in", "r", stdin);
freopen("!output.out", "w", stdout);
#else
freopen("Concert.in", "r", stdin);
freopen("Concert.out", "w", stdout);
#endif
n = read<int>();
for (int i = 1; i <= n; ++i) {
a[i].pos = read<int>(), a[i].cost = read<int>(), a[i].hear = read<int>();
}
std::sort(a + 1, a + n + 1, [](People x, People y) {
return x.pos < y.pos;
});
for (int i = 1; i <= n; ++i) {
work(a[i].pos - a[i].hear);
work(a[i].pos + a[i].hear);
}
write(ans);
return 0;
}