homes[i] is the position of house i (all positions are different). You need to place lockers parcel lockers on the road, at any points you like.
Each household walks to its nearest locker. Place the lockers so that the total distance from every house to its nearest locker is as small as possible, and return that total.homes=[2, 7, 9, 15], lockers=2 → 7
Put one locker at house 7: residents of 2, 7 and 9 walk 5 + 0 + 2 = 7. Put the other at house 15, where nobody walks. The total is 7.
homes=[6, 1, 3], lockers=3 → 0
There are as many lockers as houses, so each house gets its own.
homes=[1, 10, 20, 40, 41], lockers=2 → 20
homes=[2, 7, 9, 15], lockers=2
7
Run checks the first 3 tests in your browser. Submit checks all 100 tests on the server, hidden ones included.