← 返回 snapchat 的题目列表Find Grid Coordinate Minimizing Weighted Manhattan Distance Sum
类型:online_judge
snapchat
Given a m x n grid and a list of items (each with coordinates and quantity), find a coordinate in the grid that minimizes the product sum of Manhattan distances from this coordinate to all items. Specifically, for each grid coordinate (x, y), compute the Manhattan distance to each item (x_i, y_i), multiply these distances by the associated quantity, and sum them up. Choose the coordinate with the minimum total sum.
Example:
Input:
m = 3
n = 3
Items = [(0, 0, 1), (2, 2, 2)]
Output:
Coordinate (1, 1)
Explanation: For coordinate (1, 1), the total Manhattan distance sum is 2 * 1 + 2 * 2 = 6.
Example
Input
3 3 [(0, 0, 1), (2, 2, 2)]