On a campus represented on the X-Y plane, there are n workers and m bikes, with n ≤ m. You are given an array workers of length n where workers[i] = [xi, yi] is the position of the ith worker. You are also given an array bikes of length m where bikes[j] = [xj, yj] is the position of the jth bike.
Assign a bike to each worker using the following rules:
1. Among all available (worker, bike) pairs, choose the one with the shortest Manhattan distance
2. If there are ties, choose the pair with the smallest worker index
3. If there are still ties, choose the pair with the smallest bike index
4. Repeat until all workers have bikes
Return an array answer where answer[i] is the index of the bike assigned to the ith worker.
The Manhattan distance between two points p1 and p2 is: |p1.x - p2.x| + |p1.y - p2.y|
Input & Output
Constraints
- n == workers.length
- m == bikes.length
- 1 ≤ n ≤ m ≤ 1000
- workers[i].length == bikes[j].length == 2
- 0 ≤ workers[i][0], workers[i][1], bikes[j][0], bikes[j][1] < 1000
- All worker and bike locations are unique