/* author : Dinmukhammed ^_^ */
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sz size()
#define ll long long
#define ld long double
const int N=1e6+3;
const ll inf=1e18;
const ll MOD=1e9+7;
ll t[N*4],t1[N*4];
void build(int v=1,int tl=1,int tr=(int)1e6){
t[v]=t1[v]=inf;
if(tl==tr)return;
int md=(tl+tr)>>1;
build(v+v,tl,md);
build(v+v+1,md+1,tr);
}
void upd(int pos,ll x,int v=1,int tl=1,int tr=(int)1e6){
if(tl==tr){
t[v]=min(x,t[v]);
return;
}
int md=(tl+tr)>>1;
if(pos<=md)upd(pos,x,v+v,tl,md);
else upd(pos,x,v+v+1,md+1,tr);
t[v]=min(t[v+v],t[v+v+1]);
}
void upd1(int pos,ll x,int v=1,int tl=1,int tr=(int)1e6){
if(tl==tr){
t1[v]=min(x,t1[v]);
return;
}
int md=(tl+tr)>>1;
if(pos<=md)upd1(pos,x,v+v,tl,md);
else upd1(pos,x,v+v+1,md+1,tr);
t1[v]=min(t1[v+v],t1[v+v+1]);
}
ll get(int l,int r,int v=1,int tl=1,int tr=(int)1e6){
if(tl>=l&&tr<=r)return t[v];
if(tl>r||l>tr)return inf;
int md=(tl+tr)>>1;
return min(get(l,r,v+v,tl,md),get(l,r,v+v+1,md+1,tr));
}
ll get1(int l,int r,int v=1,int tl=1,int tr=(int)1e6){
if(tl>=l&&tr<=r)return t1[v];
if(tl>r||l>tr)return inf;
int md=(tl+tr)>>1;
return min(get1(l,r,v+v,tl,md),get1(l,r,v+v+1,md+1,tr));
}
int x[N],y[N];
bool cmp(int i,int j){
return x[i]<x[j];
}
int id[N];
void Main(){
int n,k;cin>>n>>k;
set<int>st;
vector<int>pos;
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
swap(x[i],y[i]);
st.insert(x[i]);
st.insert(y[i]);
pos.push_back(i);
}
sort(pos.begin(),pos.end(),cmp);
if(x[pos[(int)pos.sz-1]]==0){
vector<int>v;
for(int i=1;i<=n;i++)v.push_back(y[i]);
sort(v.begin(),v.end());
multiset<pair<ll,int>>st;
for(int i=1;i<(int)v.sz;i++){
id[i]=i-1;
st.insert({v[i]-v[i-1],i});
}
while(k--){
cout<<st.begin()->F<<"\n";
int i=st.begin()->S;
st.erase(st.begin());
id[i]--;
if(id[i]>=0)st.insert({v[i]-v[id[i]],i});
}
return;
}
map<int,int>mp;
int id=0;
for(auto to:st)mp[to]=++id;
if(k==1){
build();
ll ans=inf;
int id=0;
for(auto i:pos){
if(id!=0){
ans=min({ans,get(1,mp[y[i]])+(ll)x[i]+(ll)y[i],get1(mp[y[i]],(int)1e6)+(ll)x[i]-(ll)y[i]});
}
id++;
upd(mp[y[i]],-x[i]-y[i]);
upd1(mp[y[i]],y[i]-x[i]);
}
cout<<ans;
return;
}
vector<ll>v;
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
v.push_back((ll)abs(x[i]-x[j])+(ll)abs(y[i]-y[j]));
}
}
sort(v.begin(),v.end());
for(int i=0;i<k;i++)cout<<v[i]<<"\n";
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int tt=1;
// cin>>tt;
while(tt--)Main(),cout<<"\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... |