#include #include using namespace std; using namespace atcoder; typedef int64_t lint; #define rep(i, n) for(int i=0; i; using vvi = vector>; template inline void vin(vector& v) { rep(i, v.size()) cin >> v.at(i); } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template inline void drop(T x) { cout << x << endl; exit(0); } template void vout(vector v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; } constexpr lint LINF = LLONG_MAX/2; using pint = pair; using vp = vector; void dijkstra(lint start, vector &dist, vector>> &G) { lint a=0, b=0, x, y, N = G.size(); dist.resize(N, LINF); dist[start] = 0; priority_queue, greater> PQ; PQ.push(make_pair(0, start)); while (!PQ.empty()) { tie(x, a) = PQ.top(); PQ.pop(); if (dist[a] < x) continue; for (auto p : G[a]) { tie(y, b) = p; if (chmin(dist[b], x+y)) PQ.push(make_pair(x+y, b)); } } } vector>> make_graph(lint N, lint P, vp &g) { vector>> G(N); lint x, y; rep(i, N) { repx(j, i+1, N) { x = abs(g[i].first-g[j].first)+abs(g[i].second-g[j].second); G[i].pb({(x-1)/P, j}); G[j].pb({(x-1)/P, i}); } } return G; } int main() { lint N, K; cin >> N >> K; vp g(N+2); lint a=0, b=0, c=0, x, y, z; rep(i, N+2) { cin >> x >> y; g[i] = {x, y}; } lint ng = 0, mid, ok = 200100; while (ok-ng > 1) { mid = (ok+ng)/2; vector>> G = make_graph(N+2, mid, g); vi d; dijkstra(0, d, G); if (d[1] <= K) ok = mid; else ng = mid; } std::cout << ok << '\n'; }