比赛 NOIP2025模拟赛4 评测结果 AAAAAAAAAAAAAAAA
题目名称 Lunch Concert 最终得分 100
用户昵称 汐汐很希希 运行时间 2.223 s
代码语言 C++ 内存使用 7.53 MiB
提交时间 2025-11-27 09:49:49
显示代码纯文本
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
const int N=2e5+10;
const int M=1e9;
const int MOD=1e9+7;
const int MAXX=2147483647;
const int MINN=-2147483648;
ll n,ans=1e18;
struct Node{
	ll p,w,d;
	ll l,r;
}a[N];
ll work(ll x){
	ll ans=0;
	for(ll i=1;i<=n;i++){
		if(a[i].r<x) ans+=a[i].w*(x-a[i].r);
		if(a[i].l>x) ans+=a[i].w*(a[i].l-x);
	}
	return ans;
}
int main()
{
    freopen("Concert.in","r",stdin);
    freopen("Concert.out","w",stdout);
    
    cin>>n;
    for(ll i=1;i<=n;i++){
    	cin>>a[i].p>>a[i].w>>a[i].d;
    	a[i].l=a[i].p-a[i].d,a[i].r=a[i].p+a[i].d;
	}
	ll l1=-1e9,r1=1e9;
	while(l1<=r1){
		ll lmid=(2*l1+r1)/3,rmid=(l1+2*r1)/3;
		ll lans=work(lmid),rans=work(rmid);
		if(lans<=rans){
			ans=min(ans,lans);
			r1=rmid-1;
		}
		if(lans>rans){
			ans=min(ans,rans);
			l1=lmid+1;
		}
	}
	cout<<ans<<'\n';
    return 0;
}