AcWing 5201. 午餐音乐会(python3版)
原题链接
中等
作者:
newczh
,
2025-01-14 14:10:32
,
所有人可见
,
阅读 1
C++ 代码
p = []
w = []
d = []
cost = 1e18
def check(x):
global cost
res = 0
for i in range(len(p)):
if abs(x-p[i])>d[i]:
res += (abs(x-p[i])-d[i])*w[i]
cost = min(cost,res)
return res;
if __name__ == '__main__':
n = int(input())
for i in range(n):
a,b,c = map(int,input().split())
p.append(a)
w.append(b)
d.append(c)
l = 0
r = 1e9+10
while l<r:
lmid = l+(r-l)//3
rmid = r-(r-l)//3
if check(lmid)>=check(rmid): l = lmid+1
else: r = rmid-1
print(int(cost))