```
class Solution {
public:
int minDistance(int height, int width, vector<int>& tree, vector<int>& squirrel, vector<vector<int>>& nuts) {
int delta = INT32_MIN;
int total = 0;
for (const vector<int>& p : nuts) {
total += distance(p, tree) * 2;
delta = max(delta, distance(tree, p) - distance(p, squirrel));
}
return total - delta;
}
int distance(const vector<int>& p1, const vector<int>& p2) {
return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1]);
}
};
```