Untitled
unknown
c_cpp
a year ago
601 B
25
Indexable
#include <algorithm>
#include <vector>
int getMinTotalDistance(vector<int> dist_centers) {
int n = dist_centers.size();
// Sort the distribution centers
sort(dist_centers.begin(), dist_centers.end());
// Find the positions of the two warehouses
int warehouse1 = dist_centers[(n-1)/3];
int warehouse2 = dist_centers[(2*n-1)/3];
int totalDistance = 0;
// Calculate the total minimum distance
for (int center : dist_centers) {
totalDistance += min(abs(center - warehouse1), abs(center - warehouse2));
}
return totalDistance;
}Editor is loading...
Leave a Comment