#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(a, b) for(size_t a = 0; a < (b); a++)
#define pitem item*
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<ll> vl;
const int N=3e5+10;
const ll SS=1LL<<31;
struct item{
int val, id;
item *l,*r;
};
vi wyn;
vector<pair<ll,ll> >w;
bool bb[N];
vector<ll> ans,pom[N];
void Insert(pitem v,ll ind,int x,int xd,ll l=SS*(-1),ll r=SS-1){
v->val+=x;
if(l==r) {v->id=xd;return;}
ll sr=l+(r-l)/2LL;
if(ind>sr){
if(!(v->r)){
pitem xd=new item;
xd->l=nullptr,xd->r=nullptr,xd->val=0;
v->r=xd;
}
Insert(v->r,ind,x,xd,sr+1,r);
}else{
if(!(v->l)){
pitem xd=new item;
xd->l=nullptr,xd->r=nullptr,xd->val=0;
v->l=xd;
}
Insert(v->l,ind,x,xd,l,sr);
}
}
void clear(pitem v){
if(!v) return;
clear(v->l),clear(v->r);
delete v;
}
int Query(pitem v,ll pocz,ll kon,ll p=SS*(-1),ll k=SS-1){
if(p>kon or k<pocz or !v) return 0;
if(p>=pocz and k<=kon) return v->val;
else{
ll sr=p+(k-p)/2;
return Query(v->l,pocz,kon,p,sr)+Query(v->r,pocz,kon,sr+1,k);
}
}
void divide(ll l,ll r,pitem v,int k){
if(!v or (int)wyn.size()==k) return;
if(v->val==0) return;
if(l==r){
wyn.push_back(v->id);
return;
}
ll sr=l+(r-l)/2;
divide(l,sr,v->l,k),divide(sr+1,r,v->r,k);
}
void Query2(pitem v,ll pocz,ll kon,int kk,ll p=SS*(-1),ll k=SS-1){
if(p>kon or k<pocz or !v) return;
if(p>=pocz and k<=kon) divide(p,k,v,kk);
else{
ll sr=p+(k-p)/2;
Query2(v->l,pocz,kon,kk,p,sr),Query2(v->r,pocz,kon,kk,sr+1,k);
}
}
bool check(ll x,ll l){;
int wsk=0;
pitem k=new item;
k->val=0,k->l=nullptr,k->r=nullptr;
ll res=0;
rep(i,w.size()){
if(i and w[i].fi==w[i-1].fi) continue;
int curr=i;
while(w[wsk].fi<w[i].fi-x) Insert(k,w[wsk].se,-1,0),wsk++;
while(curr<(int)w.size() and w[curr].fi==w[i].fi) res+=(ll)Query(k,max(SS*(-1LL),(ll)w[curr].se-x),min(SS-1,(ll)w[curr].se+x)),Insert(k,w[curr].se,1,curr),curr++;
}
clear(k);
return res>=l;
}
ll bs(ll l){
ll pocz=1,kon=(ll)(1e9)*4;
ll sr,res=0;
while(pocz<=kon){
sr=(pocz+kon)/2;
if(check(sr,l)) res=sr,kon=sr-1;
else pocz=sr+1;
}
return res;
}
void solve(){
int n,il;
cin>>n>>il;
rep(i,n){
int x,y;
cin>>x>>y;
int x1=x-y,y1=x+y;
w.push_back({x1,y1});
}
sort(w.begin(),w.end());
ll xd=bs(il);
ll x,wsk;
if(xd>1){
x=xd-1;
pitem k=new item;
k->val=0,k->l=nullptr,k->r=nullptr;
wsk=0;
rep(i,w.size()){
if(i and w[i].fi==w[i-1].fi) continue;
int curr=i;
while(w[wsk].fi<w[i].fi-x) Insert(k,w[wsk].se,-1,0),wsk++;
while(curr<(int)w.size() and w[curr].fi==w[i].fi){
Query2(k,max(SS*(-1LL),(ll)w[curr].se-x),min(SS-1,(ll)w[curr].se+x),il),Insert(k,w[curr].se,1,curr);
pom[curr]=wyn;
rep(j,wyn.size()) ans.push_back(max(abs(w[curr].fi-w[wyn[j]].fi),abs(w[curr].se-w[wyn[j]].se)));
curr++;
wyn.clear();
}
}
clear(k);
}
sort(ans.begin(),ans.end());
rep(i,ans.size()) cout<<ans[i]<<"\n";
for(int i=ans.size();i<k;i++) cout<<xd<<"\n";
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
solve();
}
Compilation message
road_construction.cpp: In function 'void solve()':
road_construction.cpp:4:39: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
4 | #define rep(a, b) for(size_t a = 0; a < (b); a++)
| ^
road_construction.cpp:98:2: note: in expansion of macro 'rep'
98 | rep(i,n){
| ^~~
road_construction.cpp:128:25: error: 'k' was not declared in this scope
128 | for(int i=ans.size();i<k;i++) cout<<xd<<"\n";
| ^