// WEBLINK #include #include #include #include #include #include using namespace std; using ll = long long; using ii = pair; using iii = pair; using vi = vector; using vvi = vector; using vll = vector; using vii = vector; using viii = vector; #define pb push_back #define fst first #define snd second #define all(x) (x).begin,(x).end() templateT amax(T &a, T1 b) {if (b > a)a = b; return a;} templateT amin(T &a, T1 b) {if (b < a)a = b; return a;} // ---------- DEBUG -------------------- // #define ON_PC #ifdef ON_PC #include #else #define deb(x...) #endif /////////////////////////////////// void inp(ii & x) { cin >> x.fst >> x.snd; } int dis(ii x, ii y) { return abs(x.fst - y.fst) + abs(x.snd - y.snd); } int fw(ii x, ii y, int d) { return (dis(x, y) - 1) / d; } int djk(vii & A, int m) { const int inf = 10000000; int n = A.size(); vi D(n, inf); vector E(n); D[0] = 0; priority_queue Q; Q.push({0, 0}); deb(m); while (!Q.empty()) { auto p = Q.top(); Q.pop(); int x = p.second; if (E[x] or - p.first > D[x]) continue; E[x] = true; if (x == n - 1) return D[x]; for (int y = 0; y < n; y++) { if (E[y] == false) { int nd = D[x] + fw(A[x], A[y], m); if (nd < D[y]) { D[y] = nd; Q.push({ -nd, y}); } } } } return D[n - 1]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vii A(n + 2); inp(A[0]); inp(A[n + 1]); for (int i = 1; i <= n; i++) inp(A[i]); int l = 1; int h = dis(A.front(), A.back()); while (h > l) { int m = (l + h) / 2; int ret = djk(A, m); deb(l, h, m, ret, k); if (ret <= k) h = m; else l = m + 1; } cout << l << endl; return 0; }