#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;
pll points2[250001];
pll points[250001];
int n,k;
vl check(ll d)
{
vector<pll> p;
rep(i,n) p.pb(points[i]);
sort(all(p));
set<pll> cur;
int cur_del = 0;
vl ans;
int ind = 0;
forall(it,p)
{
while(cur_del < siz(p) && p[cur_del].ff < it.ff-d)
{
cur.erase(cur.find({p[cur_del].ss,cur_del}));
cur_del++;
}
ll l = it.ss-d;
ll r = it.ss+d;
vector<pll> del;
while(true)
{
auto it2 = cur.lower_bound({l,-1});
if(it2 == cur.end()) break;
if((*it2).ff > r) break;
del.pb(*it2);
cur.erase(it2);
}
ll x = (it.ff+it.ss)/2;
ll y = it.ss-x;
forall(it2,del)
{
ll x2 = (p[it2.ss].ff+p[it2.ss].ss)/2;
ll y2 = p[it2.ss].ss-x2;
ans.pb(abs(x-x2)+abs(y-y2));
if(siz(ans) == k+1) return ans;
}
forall(it,del) cur.insert(it);
cur.insert({it.ss,ind++});
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//random_start();
cin >> n >> k;
rep(i,n) cin >> points2[i].ff >> points2[i].ss;
rep(i,n) points[i] = {points2[i].ff-points2[i].ss,points2[i].ff+points2[i].ss};
ll l = 1;
ll r = 4e9;
ll ans = 0;
while(l <= r)
{
ll mid = (l+r)/2;
if(siz(check(mid)) >= k)
{
ans = mid;
r = mid-1;
}
else
{
l = mid+1;
}
}
vl ans2;
if(ans != 0) ans2 = check(ans-1);
while(siz(ans2) < k) ans2.pb(ans);
sort(all(ans2));
rep(i,k) cout << ans2[i] << "\n";
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |