#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class _T>
bool chmin(_T &x, const _T &y){
if (x>y)x=y;
return x>y;
}
template <class _T>
bool chmax(_T &x, const _T &y){
if (x<y)x=y;
return x<y;
}
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll inf=1e18+7;
const ll mod=1e9+7;
const ll N=2e5+5;
const ld eps=1e-9;
vector<pair<ll,ll>> v;
multiset<ll> ms;
ll n,k;
ll i,j,mn=inf;
map<pair<ll,ll>,bool> vis;
ll dis(ll i,ll j){
return abs(v[i].fr-v[j].fr)+abs(v[i].sc-v[j].sc);
}
bool cmp(pair<ll,ll> a,pair<ll,ll> b){
return a.sc<b.sc;
}
void upd_ans(ll i,ll j){
if(dis(i,j)>=mn || vis[{i,j}])return;
vis[{i,j}]=true;
vis[{j,i}]=true;
ms.ins(dis(i,j));
if(ms.sz>k)ms.erase(--ms.end());
if(ms.sz==k)chmin(mn,*ms.rbegin());
}
void rec(ll l,ll r){
if(r-l<3){
for(i=l;i<r;i++){
for(j=i+1;j<=r;j++)upd_ans(i,j);
}
sort(v.begin()+l,v.begin()+r+1,cmp);
return ;
}
ll m=(l+r)/2;
rec(l,m),rec(m+1,r);
vector<pair<ll,ll>> v2(r-l+1);
merge(v.begin()+l,v.begin()+m+1,v.begin()+m+1,v.begin()+r+1,v2.begin(),cmp);
for(i=l;i<=r;i++)v[i]=v2[i-l];
vll vv;
for(i=l;i<=r;i++){
if(mn<=abs(v[i].fr-v[m].fr))continue;
for(j=vv.sz-1;j>=0;j--){
if(mn<=abs(v[i].sc-v[vv[j]].sc))break;
upd_ans(i,vv[j]);
}
vv.pb(i);
}
}
void solve(){
ll i,j;
ll a,b;
cin>>n>>k;
for(i=0;i<n;i++){
cin>>a>>b;
v.pb({a,b});
}
sort(all(v));
rec(0,n-1);
while(ms.sz>k) ms.erase(--ms.end());
for(auto i : ms) cout<<i<<endl;
}
signed main(){
//start();
ll t=1;
//cin>>t;
while(t--) solve();
return 0;
}
/*
*/
Compilation message
road_construction.cpp: In function 'void upd_ans(long long int, long long int)':
road_construction.cpp:62:13: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
62 | if(ms.sz>k)ms.erase(--ms.end());
| ~~~~~^~
road_construction.cpp:63:13: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
63 | if(ms.sz==k)chmin(mn,*ms.rbegin());
| ~~~~~^~~
road_construction.cpp: In function 'void solve()':
road_construction.cpp:98:13: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
98 | while(ms.sz>k) ms.erase(--ms.end());
| ~~~~~^~
road_construction.cpp:89:7: warning: unused variable 'j' [-Wunused-variable]
89 | ll i,j;
| ^
road_construction.cpp: In function 'void fre(std::string)':
road_construction.cpp:36:27: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
road_construction.cpp:36:64: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
620 ms |
59892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2695 ms |
233048 KB |
Output is correct |
2 |
Correct |
2742 ms |
231564 KB |
Output is correct |
3 |
Correct |
364 ms |
46164 KB |
Output is correct |
4 |
Correct |
2431 ms |
252356 KB |
Output is correct |
5 |
Correct |
1732 ms |
219300 KB |
Output is correct |
6 |
Correct |
1734 ms |
219560 KB |
Output is correct |
7 |
Correct |
1838 ms |
223716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
219 ms |
13240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
219 ms |
13240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
620 ms |
59892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
620 ms |
59892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |