Skip to content

Commit d21972e

Browse files
authored
Create 2448.py
1 parent e5bae71 commit d21972e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

2401-2500/2448.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution(object):
2+
def minCost(self, A, cost):
3+
def f(x):
4+
return sum(abs(a - x) * c for a,c in zip(A, cost))
5+
6+
l, r = min(A), max(A)
7+
res = f(l)
8+
while l < r:
9+
x = (l + r) // 2
10+
y1, y2 = f(x), f(x + 1)
11+
res = min(y1, y2)
12+
if y1 < y2:
13+
r = x
14+
else:
15+
l = x + 1
16+
return res

0 commit comments

Comments
 (0)