比赛 NOIP2025模拟赛4 评测结果 AAAAAAAAAAAAAAAA
题目名称 Lunch Concert 最终得分 100
用户昵称 123 运行时间 0.935 s
代码语言 C++ 内存使用 4.82 MiB
提交时间 2025-11-27 08:42:30
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10; 
int n;
struct node {
	int p,w,d; 
} a[N];
inline int cmp(node x,node y)
{
	return x.p<y.p; 
}
long long b[N];
inline void read(int &x)
{
	int cnt=0;
	char c=getchar();
	while (!('0'<=c && c<='9')) c=getchar();
	while ('0'<=c && c<='9') cnt=cnt*10+(c-'0'),c=getchar();
	x=cnt;
}
long long check(int mid)
{
	long long cnt=0;
	for (int i=1;i<=n;i++)
	{
		if (!(mid-a[i].d<=a[i].p && a[i].p<=mid+a[i].d))
		{
			if (a[i].p<mid-a[i].d) cnt+=1ll*(mid-a[i].d-a[i].p)*a[i].w;
			else cnt+=1ll*(a[i].p-(mid+a[i].d))*a[i].w;
		}
	}
	return cnt;
}
int main() {
	freopen("Concert.in","r",stdin);
	freopen("Concert.out","w",stdout); 
	read(n);
	for (int i=1;i<=n;i++) read(a[i].p),read(a[i].w),read(a[i].d);
	int l=0,r=1e9;
	while (l<r)
	{
		int mid=(l+r+1)/2;
		if (check(mid-1)>=check(mid)) l=mid;
		else r=mid-1;
	} 
	cout<<check(l);
}