mirror of
https://github.com/tiennm99/claoj.git
synced 2026-06-17 18:48:03 +00:00
100 lines
2.3 KiB
C++
100 lines
2.3 KiB
C++
#include <iostream>
|
|
#include <vector>
|
|
#include <algorithm>
|
|
#include <climits>
|
|
using namespace std;
|
|
|
|
typedef long long ll;
|
|
|
|
struct Point {
|
|
ll x, y;
|
|
};
|
|
|
|
ll manhattan(const Point &a, const Point &b) {
|
|
return abs(a.x - b.x) + abs(a.y - b.y);
|
|
}
|
|
|
|
bool isPossible(ll D, const vector<Point> &chargers, const Point &start, ll N) {
|
|
ll u0 = start.x + start.y;
|
|
ll v0 = start.x - start.y;
|
|
ll min_u = u0 - N;
|
|
ll max_u = u0 + N;
|
|
ll min_v = v0 - N;
|
|
ll max_v = v0 + N;
|
|
|
|
vector<ll> u_candidates = {min_u, max_u, u0};
|
|
vector<ll> v_candidates = {min_v, max_v, v0};
|
|
|
|
for (const Point &c: chargers) {
|
|
ll cu = c.x + c.y;
|
|
ll cv = c.x - c.y;
|
|
u_candidates.push_back(cu - D);
|
|
u_candidates.push_back(cu + D);
|
|
v_candidates.push_back(cv - D);
|
|
v_candidates.push_back(cv + D);
|
|
}
|
|
|
|
sort(u_candidates.begin(), u_candidates.end());
|
|
u_candidates.erase(unique(u_candidates.begin(), u_candidates.end()), u_candidates.end());
|
|
|
|
sort(v_candidates.begin(), v_candidates.end());
|
|
v_candidates.erase(unique(v_candidates.begin(), v_candidates.end()), v_candidates.end());
|
|
|
|
for (ll u: u_candidates) {
|
|
for (ll v: v_candidates) {
|
|
if (u < min_u || u > max_u || v < min_v || v > max_v) continue;
|
|
|
|
ll x = (u + v) / 2;
|
|
ll y = (u - v) / 2;
|
|
|
|
if ((u + v) % 2 != 0) continue;
|
|
|
|
Point p = {x, y};
|
|
if (manhattan(p, start) > N) continue;
|
|
|
|
bool valid = true;
|
|
for (const Point &c: chargers) {
|
|
if (manhattan(p, c) < D) {
|
|
valid = false;
|
|
break;
|
|
}
|
|
}
|
|
if (valid) return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
int main() {
|
|
ios_base::sync_with_stdio(false);
|
|
cin.tie(NULL);
|
|
|
|
int U;
|
|
ll N;
|
|
cin >> U >> N;
|
|
|
|
vector<Point> chargers(U);
|
|
for (int i = 0; i < U; i++) {
|
|
cin >> chargers[i].x >> chargers[i].y;
|
|
}
|
|
|
|
Point start;
|
|
cin >> start.x >> start.y;
|
|
|
|
ll left = 0;
|
|
ll right = 4e9;
|
|
|
|
while (left <= right) {
|
|
ll mid = left + (right - left) / 2;
|
|
if (isPossible(mid, chargers, start, N)) {
|
|
left = mid + 1;
|
|
} else {
|
|
right = mid - 1;
|
|
}
|
|
}
|
|
|
|
cout << right << endl;
|
|
|
|
return 0;
|
|
}
|