i stands at couriers[i] = [x, y] and scooter j sits at scooters[j] = [x, y]. There are at least as many scooters as couriers.
Every courier must get a scooter of their own (no scooter goes to two couriers). A courier walks to their scooter along the Manhattan distance |x1 - x2| + |y1 - y2|.
Return the smallest possible total distance walked by all the couriers.couriers=[[0, 0], [5, 5]], scooters=[[4, 4], [1, 1], [9, 0]] → 4
Courier 0 takes scooter 1 (walk 2) and courier 1 takes scooter 0 (walk 2), 4 in total; scooter 2 stays unused.
couriers=[[0, 0], [2, 0]], scooters=[[1, 0], [6, 0]] → 5
Either courier 0 takes scooter 0 and courier 1 takes scooter 1 (1 + 4 = 5), or the other way round (6 + 1 = 7). The answer is 5.
couriers=[[3, 3]], scooters=[[3, 3]] → 0
The scooter is right where the courier stands, so no walking at all.
[x, y] with 0 ≤ x, y < 1000couriers=[[0, 0], [5, 5]], scooters=[[4, 4], [1, 1], [9, 0]]
4
Run checks the first 3 tests in your browser. Submit checks all 89 tests on the server, hidden ones included.