#include using namespace std; struct UnionFind { int n; vector par, siz; UnionFind(int n_) : n(n_), par(n_, -1), siz(n_, 1) {} int leader(int x) { if (par[x] == -1) { return x; } else { return par[x] = leader(par[x]); } } bool same(int x, int y) { return leader(x) == leader(y); } bool merge(int x, int y) { x = leader(x); y = leader(y); if (x == y) { return false; } if (siz[x] < siz[y]) { swap(x, y); } par[y] = x; siz[x] += siz[y]; return true; } int size(int x) { return siz[leader(x)]; } vector> groups() { vector> member(n); for (int i = 0; i < n; i++) { member[leader(i)].push_back(i); } vector> result; for (int i = 0; i < n; i++) { if (member[i].size() > 0) { result.push_back(member[i]); } } return result; } }; int main() { int h, w, n, d; cin >> h >> w >> n >> d; vector x(n), y(n); map, int> mp; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; mp[{x[i], y[i]}] = i + 1; } UnionFind uf(n); for (int i = 0; i < n; i++) { int a = x[i], b = y[i]; for (int j = -d; j <= d; j++) { for (int k = -d; k <= d; k++) { if (abs(j) + abs(k) > d) { continue; } int na = a + j, nb = b + k; int id = mp[{na, nb}]; if (id > 0) { uf.merge(i, id - 1); } } } } set s; for (int i = 0; i < n; i++) { int ld = uf.leader(i); if (uf.size(ld) >= 2) { s.insert(ld); } } int sz = s.size(); //周りにある星座の種類数 int mx = 0, mn = 2000000000; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { if (mp[{i, j}] > 0) { continue; } int now = sz; set tmp; for (int k = -d; k <= d; k++) { for (int l = -d; l <= d; l++) { if (abs(k) + abs(l) > d) { continue; } int ni = i + k, nj = j + l; int id = mp[{ni, nj}]; if (id > 0) { tmp.insert(uf.leader(id - 1)); } } } bool ok = false; for (int star : tmp) { if (s.count(star)) { ok = true; } } if (tmp.size() > 0) { now = (ok ? now - (int)tmp.size() + 1 : now + 1); } mx = max(mx, now); mn = min(mn, now); } } cout << mn << " " << mx << endl; }