#include using namespace std; #define endl "\n" #define int long long const int MOD = 998244353; bool check(int x, int n, int k, int sx, int sy, int gx, int gy, vector> &lamps) { int ans = 1e18; vector dp(n, 1e9); for (int i = n - 1; i >= 0; i--) { if(lamps[i].first > gx) { continue; } int dist = abs(lamps[i].first - gx) + abs(lamps[i].second - gy); dp[i] = max((dist / x) - (dist % x == 0), 0LL); for (int j = i + 1; j < n; j++) { int dist = abs(lamps[j].first - lamps[i].first) + abs(lamps[j].second - lamps[i].second); dp[i] = min(dp[i], dp[j] + max((dist / x) - (dist % x == 0), 0LL)); } int temp = 0; dist = abs(lamps[i].first - sx) + abs(lamps[i].second - sy); temp = max((dist / x) - (dist % x == 0), 0LL); ans = min(ans, temp + dp[i]); } return ans <= k; } // int binary_search(int l, int r) { // while (l < r) { // int m = l + (r - l) / 2; // if (check(m)) { // r = m; // } else { // l = m + 1; // } // } // return l; // } void solve() { int n, k; cin >> n >> k; int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; vector> lamps(n); for (int i = 0; i < n; i++) { cin >> lamps[i].first >> lamps[i].second; } sort(lamps.begin(), lamps.end()); if(sx > gx) { swap(sx, gx); swap(sy, gy); } int l = 1, r = 200005; // auto check = [&](int x) -> bool{ // // 1d dp to check if we can reach the destination with x visibility // int ans = 1e18; // vector dp(n, 0); // for (int i = n - 1; i >= 0; i--) { // int dist = abs(lamps[i].first - gx) + abs(lamps[i].second - gy); // if(dist > x) { // dp[i] = (dist / (2 * x)) + (dist % (2 * x) != 0); // } // for (int j = i + 1; j < n; j++) { // int dist = abs(lamps[j].first - lamps[i].first) + abs(lamps[j].second - lamps[i].second); // if(dist > x) { // dp[i] = max(dp[i], dp[j] + (dist / (2 * x)) + (dist % (2 * x) != 0)); // } // } // int temp = 0; // dist = abs(lamps[i].first - sx) + abs(lamps[i].second - sy); // if(dist > x) { // temp = (dist / (2 * x)) + (dist % (2 * x) != 0); // } // ans = min(ans, temp + dp[i]); // } // return ans <= k; // }; while (l < r) { int m = l + (r - l) / 2; if (check(m, n, k, sx, sy, gx, gy, lamps)) { r = m; } else { l = m + 1; } } cout << l << endl; } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); int T = 1; // cin >> T; while (T--) { solve(); } return 0; }