Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <cassert>
- #include <cstdio>
- #include <iostream>
- #include <set>
- #include <map>
- #include <set>
- #include <queue>
- #include <vector>
- using namespace std;
- typedef long long int64_t;
- const int N = 100000;
- int n, C;
- pair<int, int> points[N];
- vector<int> edges[N];
- int component[N];
- int csize[N];
- int cc;
- int main() {
- cin >> n >> C;
- for (int i = 0; i < n; i++) {
- int x, y;
- cin >> x >> y;
- points[i].first = x + y;
- points[i].second = x - y;
- }
- sort(points, points + n);
- set<pair<int, int>> ys;
- int li = 0;
- for (int i = 0; i < n; i++) {
- int x = points[i].first;
- int y = points[i].second;
- while (li < i && points[li].first + C < x) {
- ys.erase(make_pair(points[li].second, li));
- li++;
- }
- auto it = ys.lower_bound(make_pair(y, i));
- if (it != ys.begin()) {
- it--;
- }
- for (int j = 0; j < 2 && it != ys.end(); j++, it++)
- if (abs(it->first - y) <= C) {
- edges[i].push_back(it->second);
- edges[it->second].push_back(i);
- }
- ys.insert(make_pair(y, i));
- }
- cc = 0;
- for (int i = 0; i < n; i++) {
- if (component[i] == 0) {
- component[i] = ++cc;
- csize[i] = 1;
- queue<int> qu;
- qu.push(i);
- while (!qu.empty()) {
- int x = qu.front();
- qu.pop();
- for (auto nx : edges[x]) {
- if (component[nx] == 0) {
- component[nx] = cc;
- csize[i]++;
- qu.push(nx);
- }
- }
- }
- }
- }
- int mx = 0;
- for (auto x : csize) {
- mx = max(x, mx);
- }
- cout << cc << " " << mx << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement