// #define _GLIBCXX_DEBUG #include using namespace std; #include using namespace atcoder; using ll = long long; #define rep(i,n) for (ll i = 0; i < (n); ++i) using vl = vector; using vvl = vector; using P = pair; #define pb push_back #define int long long #define double long double #define INF (ll) 3e18 // Ctrl + Shift + B コンパイル // Ctrl + C 中断 // ./m 実行 signed main(){ int n, k; cin >> n >> k; int ok = 1000000; int ng = 0; int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; vector

xy(n); rep(i,n) cin >> xy[i].first >> xy[i].second; xy.emplace_back(sx, sy); xy.emplace_back(gx, gy); n = xy.size(); vector> E(n); // 重み付きグラフへ rep(i,n){ rep(j,n){ if (i == j) continue; E[i].emplace_back(j, abs(xy[i].first-xy[j].first) + abs(xy[i].second-xy[j].second)); } } while(ok - ng != 1){ int mid = (ok + ng) / 2; priority_queue, greater

> pq; pq.emplace(0, n-2); vl dist(n, INF); dist[n-2] = 0; while(pq.size()){ auto [cost, now] = pq.top(); pq.pop(); if (dist[now] != cost) continue; for(auto [to, w] : E[now]){ if (dist[to] <= cost + (w-1) / mid) continue; dist[to] = cost + (w-1) / mid; pq.emplace(dist[to], to); } } if (dist[n-1] <= k) ok = mid; else ng = mid; } cout << ok << endl; } // 単に明かりを配置すればよいわけではなく // 例えば k = 2 (0,0) (6,6)なら // (3,3)においてはダメで、2,2 4,4 と配置する // Nが小さいので、視界で二分探索すればよいのではないか。