| 比赛 |
NOIP2025模拟赛4 |
评测结果 |
AAAAAAAAAAAAAAAA |
| 题目名称 |
Lunch Concert |
最终得分 |
100 |
| 用户昵称 |
淮淮清子 |
运行时间 |
2.315 s |
| 代码语言 |
C++ |
内存使用 |
5.97 MiB |
| 提交时间 |
2025-11-27 09:30:18 |
显示代码纯文本
#include<iostream>
#include<ctime>
using namespace std;
#define int long long
const int MAXN = 2 * 1e5 + 5;
int n;
struct node{
int p, w, d;
}peo[MAXN];
/*
check function is ok
O(n)
*/
int check(int x){
int res = 0;
for(int i = 1;i <= n;i ++){
int f = abs(x - peo[i].p) - peo[i].d;
if(f <= 0) continue;
else{
res += f * peo[i].w;
}
}
return res;
}
signed main(){
freopen("Concert.in", "r", stdin);
freopen("Concert.out", "w", stdout);
cin >> n;
for(int i = 1;i <= n;i ++){
cin >> peo[i].p >> peo[i].w >> peo[i].d;
}
// cout << check(4) << '\n';
// cout << check(5) << '\n';
// cout << check(6) << '\n';
int l = -1e9, r = 1e9 + 10;
int ans = 1e18;
while(l <= r){
int mid1 = (2 * l + r) / 3;
int mid2 = (l + 2 * r) / 3;
int val1 = check(mid1), val2 = check(mid2);
ans = min(val1, ans);
ans = min(val2, ans);
if(val1 <= val2){
r = mid2 - 1;
}
else{
l = mid1 + 1;
}
}
ans = min(check(l), ans);
ans = min(check(r), ans);
cout << ans << '\n';
// cerr << "Time : " << 1.0 * clock() / CLOCKS_PER_SEC << "s \n";
return 0;
}
/*
2 5 3
10 4 2
\sum {(|p_i - x| - d_i) * w_i}
ans is same as quadratic function
4 : 16
5 : 12
6 : 13
*/